Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert NSArray into NSString

How to convert NSArray into NSString in objective-c?

like image 644
Arun K Sharma Avatar asked Mar 05 '10 12:03

Arun K Sharma


People also ask

Can we use NSArray in Swift?

In Swift, the NSArray class conforms to the ArrayLiteralConvertible protocol, which allows it to be initialized with array literals. For more information about object literals in Swift, see Literal Expression in The Swift Programming Language (Swift 4.1).

Can NSArray contain nil?

arrays can't contain nil. There is a special object, NSNull ( [NSNull null] ), that serves as a placeholder for nil.

What is NSArray?

NSArray(NSCoder) A constructor that initializes the object from the data stored in the unarchiver object.

Is NSArray ordered?

In Objective-C, arrays take the form of the NSArray class. An NSArray represents an ordered collection of objects. This distinction of being an ordered collection is what makes NSArray the go-to class that it is.


2 Answers

Swift 3.0 latest updates

let string = array.componentsJoined(by: ",")

you can used any separator in function which you want to separate the array elements currently in above example is ",".

like image 77
Chavda jaydeep Avatar answered Sep 18 '22 00:09

Chavda jaydeep


Bearing in mind that you don't say what's in the NSArray, you can do this:

NSArray *arr = [NSArray arrayWithObjects: @"foo", @"bar", @"baz"];
[arr componentsJoinedByString: @","]
like image 35
Frank Shearar Avatar answered Sep 20 '22 00:09

Frank Shearar