Swift - How to create an array of string from an object array

时间:2016-07-11 22:46:40

标签: swift swift2

I have the following class:

class ServicePaymentRate : AnyObject {

    var servicePaymentRateUid : String = ""
    var servicePaymentCode : String = ""
    var description : String = ""
    var paymentPercentage : Float = 0
    var isPrimary : Bool = false
    var isFacility : Bool = false

}

Then the class is popullated in order to get an array of that class:

var rates : Array<ServicePaymentRate>

What I need now is to create a String array from the above object array by filtering description property. That way I will have a string array that will contain only description property values.

Any clue

1 个答案:

答案 0 :(得分:4)

let descriptions = rates.map { $0.description }