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?
You can reverse a NSArray by writing your own loop iterating from the end towards the beginning and using a second array to add the items in reverse order. Or you can simply use - (NSEnumerator *)reverseObjectEnumerator from the NSArray class.
Yes, NSArray is faster than NSSet for simply holding and iterating. As little as 50% faster for constructing and as much as 500% faster for iterating.
An NSDictionary will retain it's objects, and copy it's keys.
Since -allObjects returns an array, you can create a mutable version with:
NSMutableArray *array = [NSMutableArray arrayWithArray:[set allObjects]]; Or, alternatively, if you want to handle the object ownership:
NSMutableArray *array = [[set allObjects] mutableCopy];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With