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
25
votes
4 answers

NSArray objectAtIndex: shorthand

Possible Duplicate: Is there some literal dictionary or array syntax in Objective-C? I have recently noticed that something strange seems to work in objective-c. When I have an array, NSArray *myArray = @[@"1", @"b", @"3", @"d"]; I can normally…
George Green
  • 4,807
  • 5
  • 31
  • 45
25
votes
2 answers

Filter Array with dictionaries using NSPredicate

There is an Array with each element being a NSDictionary. NSMutableArray *mutArr = [NSMutableArray array]; for (Person *person in persons) { NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:person.name, @"name", person.email,…
lu yuan
  • 7,207
  • 9
  • 44
  • 78
24
votes
8 answers

Search NSArray for value matching value

I have an NSArray of objects, which has a particular property called name (type NSString). I have a second NSArray of NSStrings which are names. I'd like to get an NSArray of all the objects whose .name property matches one of the names in the…
Jonathan.
  • 53,997
  • 54
  • 186
  • 290
24
votes
2 answers

Which has faster performance indexesOfObjectsPassingTest or filteredArrayUsingPredicate?

When needing to filter an NSArray to get a subset of the items in the array returned, which method is quicker more frequently and in edge cases?
Henry Heleine
  • 673
  • 2
  • 9
  • 28
24
votes
4 answers

How to check if an instance of NSMutableArray is null or not

How to check an NSMutableArray is null or not ?
S.P.
  • 5,427
  • 11
  • 56
  • 83
24
votes
1 answer

How can I get all values for specific key from each NSDictionary in an NSArray?

I have an array which contains dictionary objects. In each dictionary the key are common. Now I want to get all the values of that key. I have got these values with iteration, but I am looking for some straight forward way or a default method which…
hgpl
  • 869
  • 4
  • 11
  • 20
24
votes
10 answers

Fastest way to check if an array contains the same objects of another array

The goal is to compare two arrays as and check if they contain the same objects (as fast as possible - there are lots of objects in the arrays). The arrays cannot be checked with isEqual: as they are differently sorted. I already tried the solution…
FrankZp
  • 2,022
  • 3
  • 28
  • 41
23
votes
7 answers

How to add objects to an NSArray using for loop?

I want to add the [NSDecimalNumber numberWithInt:i] to an array using for loop. It is hardcoded : NSArray *customTickLocations = [NSArray arrayWithObjects: [NSDecimalNumber numberWithInt:1],[NSDecimalNumber numberWithInt:2],[NSDecimalNumber…
Madan Mohan
  • 8,764
  • 17
  • 62
  • 96
23
votes
3 answers

How to convert NSArray to NSMutableArray

ABAddressBookRef addressBook = ABAddressBookCreate(); CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook); CFIndex nPeople = ABAddressBookGetPersonCount(addressBook); NSMutableArray *tempPeoples=[[NSMutableArray…
Ali
  • 10,774
  • 10
  • 56
  • 83
23
votes
1 answer

Ambiguous reference to member 'joinWithSeparator' in swift

I'm using Google's 'reverseGeocodeCoordinate' to get address based on latitude and longitude. I'm getting the following error in the implementation Ambiguous reference to member 'joinWithSeparator' Below is my implementation: let aGMSGeocoder:…
Ashok
  • 5,585
  • 5
  • 52
  • 80
23
votes
2 answers

Why does a (copy, nonatomic) NSMutableArray property create NSArrays?

I made a mistake while creating a TableView class, and accidentally kept my @property as copy when I defined it: @property (copy, nonatomic) NSMutableArray *words; I initialised the array "correctly": (note this is the third attempt, so please…
Akshay Rangnekar
  • 272
  • 2
  • 11
22
votes
5 answers

How to add an NSMutableArray to an NSMutableArray Objective-c

I am making the switch from Java to Objective-c, and I'm having some difficulty. I have searched this problem this without much success. I have an NSMutableArray that stores NSMutableArrays. How do I add an array to the array?
novicePrgrmr
  • 18,647
  • 31
  • 81
  • 103
22
votes
3 answers

How might I check if a particular NSString is present in an NSArray?

How might I check if a particular NSString is presnet in an NSArray?
Ravi
  • 1,759
  • 5
  • 20
  • 38
22
votes
4 answers

NSArray property: copy or retain?

According to this: NSString property: copy or retain? For NSString/NSMutableString, copy is recommended. How about NSArray/NSMutableArray?
Howard
  • 19,215
  • 35
  • 112
  • 184
22
votes
8 answers

Objective C: how to check if variable is NSArray or NSMutableArray

How can i check if a variable is an NSArray or an NSMutableArray?
Alexander
  • 1,121
  • 2
  • 10
  • 6