Questions tagged [nsset]

NSSet declares the programmatic interface for static sets of distinct objects.Available in OS X v10.0 and later which is inherited from NSObject

NSSet declares the programmatic interface for static sets of distinct objects. You establish a static set’s entries when it’s created, and thereafter the entries can’t be modified.

NSSet is "toll-free bridged" with its Core Foundation counterpart, CFSetRef. See "Toll-Free Bridging" for more information on toll-free bridging.

You can use sets as an alternative to arrays when the order of elements isn’t important and performance in testing whether an object is contained in the set is a consideration—while arrays are ordered, testing for membership is slower than with sets.

The question related to this can be tagged with , , tags

Creating Sets

  NSSet *setObjs = [NSSet setWithObjects:@"Chrysler",
                                         @"Ford",
                                         @"General Motors", nil];

Resources:

385 questions
106
votes
3 answers

How to return an NSMutableArray from an NSSet

I'm able to put the contents of an NSSet into an NSMutableArray like this: NSMutableArray *array = [set allObjects]; The compiler complains though because [set allObjects] returns an NSArray not an NSMutableArray. How should this be fixed?
node ninja
  • 31,796
  • 59
  • 166
  • 254
97
votes
8 answers

Getting an object from an NSSet

If you can't get an object with objectAtIndex: from an NSSet then how do you retrieve objects?
node ninja
  • 31,796
  • 59
  • 166
  • 254
68
votes
6 answers

What is the most efficient way to sort an NSSet?

What's the most efficient way to sort objects in an NSSet/NSMutableSet based on a property of the objects in the set? Right now the way I am doing it is by iterating through each object, add them to a NSMutableArray, and sort that array with…
Boon
  • 40,656
  • 60
  • 209
  • 315
67
votes
1 answer

Creating an array from properties of objects in another array

Is there any convenient way to take an array/set of objects and create a new array/set containing some property of each item in the first array? For example, an array contains Car objects. I need an array of licensePlates, where each car has an…
Ben Packard
  • 26,102
  • 25
  • 102
  • 183
59
votes
11 answers

How to create array of unique object list in Swift

How can we create unique object list in Swift language like NSSet & NSMutableSet in Objective-C.
Subramanian P
  • 4,365
  • 2
  • 21
  • 25
53
votes
4 answers

How to search an NSSet or NSArray for an object which has an specific value for an specific property?

How to search an NSSet or NSArray for an object which has an specific value for an specific property? Example: I have an NSSet with 20 objects, and every object has an type property. I want to get the first object which has [theObject.type…
dontWatchMyProfile
  • 45,440
  • 50
  • 177
  • 260
51
votes
1 answer

Why doesn't NSOrderedSet inherit from NSSet?

Surely an ordered set is a more-specific case of a set, so why does NSOrderedSet inherit from NSObject rather than NSSet?
jhabbott
  • 18,461
  • 9
  • 58
  • 95
50
votes
6 answers

NSSet to NSArray casting calling objectAtIndex?

I'm trying to update an MKMapView by removing all annotations outside the visible area, and adding and removing some annotations inside the visible area. This is my code: NSSet *visibleAnnotations = [mapView annotationsInMapRect:[mapView…
benwad
  • 6,414
  • 10
  • 59
  • 93
49
votes
2 answers

Objective-C literals for NSSet and NSOrderedSet?

What, if any, NSSet and NSOrderedSet operations can one perform with the new Objective-C collection literals? For NSArray, NSDictionary, and NSNumber, see here. FWIW, this Big Nerd Ranch Post says the indexing syntax is supposed to work for…
William Jockusch
  • 26,513
  • 49
  • 182
  • 323
32
votes
2 answers

NSArray from NSSet - Do I have to sort it myself?

I've got data in an NSSet, and I need to get it into an NSArray. Do I need to sort it myself (again, this came from Core Data) or can I get it out in a sorted order?
Jeff
  • 4,751
  • 5
  • 31
  • 35
30
votes
1 answer

Does NSSet's containsObject: test for pointer equality or value equality?

Say I have an NSSet with a string in it. If I send containsObject: with another string which is a different pointer but the exact same string value, will that return YES? Also, is it the same story when it comes to removeObject:? I.e., different…
Chris
  • 39,719
  • 45
  • 189
  • 235
28
votes
5 answers

How to turn an NSArray of strings into an array of unique strings, in the same order?

If you have an NSArray of strings { @"ONE", @"ONE", @"ONE", "TWO", @"THREE", @"THREE" } How would I turn that into { @"ONE", @"TWO", @"THREE" } ..where the array follows the same order as the original. I think that you can turn an array into an…
cannyboy
  • 24,180
  • 40
  • 146
  • 252
28
votes
3 answers

How do I put objects in an NSArray into an NSSet?

I have some NSDictionary objects stored in an NSArray called telephoneArray. I fetch the values for the key number and then replace the NSDictionary I've just read with a new object at the same index in the array. I then want to put these new…
conorgriffin
  • 4,282
  • 7
  • 51
  • 88
21
votes
1 answer

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?
nfm
  • 19,689
  • 15
  • 60
  • 90
19
votes
2 answers

Does NSSet use hash to define uniqueness?

I've been working under the assumption that NSSet used hash to look up potential matches, and then called isEqual on each of those to check for real collisions, but I realized that I can't find any evidence to back this up. The reason I bring it up…
DougW
  • 28,776
  • 18
  • 79
  • 107
1
2 3
25 26