VAAA VAAA - 4 months ago 8
Swift Question

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

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

Answer

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