Questions tagged [nsarray]

An immutable, integer-indexed array of objects from the Apple Foundation framework.

An NSArray object manages an immutable array; once you have created the array, you cannot add, remove, or replace the objects in the array. You can, however, modify the individual elements themselves (if they support modification). The mutability of the collection does not affect the mutability of the objects inside the collection. You should use an immutable array if your data rarely changes, or changes all at once. Consider using a mutable array () if your data changes frequently.

Resources:

5346 questions
62
votes
3 answers

Difference between NSArray and NSMutableArray

What is the difference b/w NSArray and NSMutableArray?
g.revolution
  • 11,962
  • 23
  • 81
  • 107
56
votes
2 answers

iPhone - getting unique values from NSArray object

I have an NSArray formed with objects of a custom class. The class has 3 (city, state, zip) string properties. I would like to get all unique state values from the array. I did read through the NSPredicate class but couldn't make much of how to use…
lostInTransit
  • 70,519
  • 61
  • 198
  • 274
54
votes
6 answers

Use NSArray to specify otherButtonTitles?

UIAlertSheet's constructor takes an otherButtonTitles parameter as a varg list. I'd like to specify the other button titles from an NSArray instead. Is this possible? i.e. I have to do this: id alert = [[UIActionSheet alloc] initWithTitle:…
Steven Fisher
  • 44,462
  • 20
  • 138
  • 192
53
votes
4 answers

Finding maximum numeric value in NSArray

I have an NSArray of NSNumbers and want to find the maximum value in the array. Is there any built in functionality for doing so? I am using iOS4 GM if that makes any difference.
Adam S.
  • 1,251
  • 1
  • 12
  • 16
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
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
50
votes
9 answers

Static NSArray of strings - how/where to initialize in a View Controller

In a Master-Detail app I'd like to display a TableView with 5 sections titled: Your Move Their Move Won Games Lost Games Options So I create a blank Master-Detail app in Xcode 5.0.2 and then in its MasterViewController.m (which is a…
Alexander Farber
  • 21,519
  • 75
  • 241
  • 416
49
votes
4 answers

How to separate string by space using Objective-C?

Assume that I have a String like this: hello world this may have lots of sp:ace or little space I would like to seperate this String to this: @"hello", @"world", @"this", @"may", @"have", @"lots", @"of", @"sp:ace", @"or",…
user448236
  • 683
  • 2
  • 7
  • 13
49
votes
5 answers

Finding smallest and biggest value in NSArray of NSNumbers

What's an effective and great way to compare all the values of NSArray that contains NSNumbers from floats to find the biggest one and the smallest one? Any ideas how to do this nice and quick in Objective-C?
Sergey Grischyov
  • 11,995
  • 20
  • 81
  • 120
47
votes
7 answers

NSArray + remove item from array

How to remove an item from NSArray.
pratik
  • 4,419
  • 8
  • 41
  • 65
46
votes
4 answers

Beautify NSLog of NSArray & NSDictionary

I'm dealing with deeply nested NSArray's and NSDictionary's and it's very time consuming to say the least. [data objectatindex:0] valueForKey:@"blah"] etc etc Does anyone know of a nice iOS category to recursively log the structure, highlight the…
iOSDevil
  • 1,786
  • 3
  • 16
  • 29
46
votes
6 answers

Convert NSArray to NSDictionary

How can I convert an NSArray to an NSDictionary, using an int field of the array's objects as key for the NSDictionary?
johnl
  • 557
  • 2
  • 5
  • 7
44
votes
6 answers

How do I remove leading & trailing whitespace of NSString inside an NSArray?

I have an NSArray declared as such: @property (nonatomic, strong) NSArray *arrayRefineSubjectCode; I have the array elements manually filled out as below: arrayRefineSubjectCode = [NSArray arrayWithObjects: @" …
shamsulfakhar
  • 563
  • 1
  • 4
  • 7
44
votes
3 answers

Objective-C: `continue` in collection enumeration block?

If I have an NSArray and I use enumerateUsingBlock to loop through elements in the array, but in some cases I need to skip the loop body and go to next element, is there any continue equivalent in block, or can I use continue…
hzxu
  • 5,753
  • 11
  • 60
  • 95
43
votes
4 answers

How to get the last object of an NSArray

So I have an array which the amount of items could vary. I was wondering if there is anyway I can get the last object of an NSArray? I did think of having like an int counter to trace the amount of items in the array however that seems too much of a…
TheAmateurProgrammer
  • 9,252
  • 8
  • 52
  • 71