Objective-C Simplest way to create comma separated string from an array of objects

后端 未结 4 878
既然无缘
既然无缘 2021-01-30 19:49

So I have a nsmutablearray with a bunch of objects in it. I want to create a comma separated string of the id value of each object.

4条回答
  •  天涯浪人
    2021-01-30 20:34

    If you're searching for the same solution in Swift, you can use this:

    var array:Array = ["string1", "string2", "string3"]
    var commaSeperatedString = ", ".join(array) // Results in string1, string2, string3
    

    To make sure your array doesn't contains nil values, you can use a filter:

    array = array.filter { (stringValue) -> Bool in
        return stringValue != nil && stringValue != ""
    }
    

提交回复
热议问题