Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I join an NSSet's elements to create an NSString?

If I have an NSSet of NSString objects, how can I join them together to create a single NSString?

like image 842
nfm Avatar asked May 17 '11 01:05

nfm


People also ask

How to create NSSet?

An NSSet can be created through the setWithObjects: class method, which accepts a nil -terminated list of objects. Most of the examples in this module utilize strings, but an NSSet instance can record any kind of Objective-C object, and it does not have to be homogeneous.

What's a difference between NSArray and NSSet?

The main difference is that NSArray is for an ordered collection and NSSet is for an unordered collection. There are several articles out there that talk about the difference in speed between the two, like this one. If you're iterating through an unordered collection, NSSet is great.

What Is NSSet In swift?

NSSet declares the programmatic interface for static sets of distinct objects. You establish a static set's entries when it's created, and can't modify the entries after that. NSMutableSet , on the other hand, declares a programmatic interface for dynamic sets of distinct objects.


1 Answers

NSSet's -allObjects method will return an NSArray of objects in the receiver.

So, knowing this, it's pretty simple:

[[set allObjects] componentsJoinedByString:@" "];
like image 83
Jacob Relkin Avatar answered Oct 22 '22 12:10

Jacob Relkin