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
43
votes
10 answers

Non-retaining array for delegates

In a Cocoa Touch project, I need a specific class to have not only a single delegate object, but many of them. It looks like I should create an NSArray for these delegates; the problem is that NSArray would have all these delegates retained, which…
wh1t3cat1k
  • 3,146
  • 6
  • 32
  • 38
43
votes
3 answers

indexOfObject vs. indexOfObjectIdenticalTo

What is the difference between these two NSArray methods?
William Jockusch
  • 26,513
  • 49
  • 182
  • 323
42
votes
2 answers

Comma-separated string to NSArray in Objective-C

So I have no experience with arrays... But I need to use one to populate a UIPickerView. I am obtaining a list of objects via HTTP (NSURLConnection). This works fine. Currently, the response is stored in a NSString as a comma-separated list. I need…
whitebreadb
  • 525
  • 2
  • 6
  • 6
42
votes
3 answers

Concatenation of two arrays in Objective-C

How to concatenate two arrays into a single array in Objective-C?
Kiran
  • 551
  • 2
  • 7
  • 13
42
votes
5 answers

Initialize Array of Objects using NSArray

I'm pretty new to Objective-C and iOS so I've been playing around with the Picker View. I've defined a Person Class so that when you create a new Person it automatically gives that person a name and age. #import "Person.h" @implementation…
Howdy_McGee
  • 10,422
  • 29
  • 111
  • 186
41
votes
6 answers

NSArray @property backed by a NSMutableArray

I've defined a class where I'd like a public property to appear as though it is backed by an NSArray. That is simple enough, but in my case the actual backing ivar is an NSMutableArray: @interface Foo { NSMutableArray* array; } @property…
Matty P
  • 881
  • 1
  • 7
  • 11
41
votes
3 answers

NSArray adding elements

I have to create a dynamic NSArray, that is, I don't know the size of the array or what elements the array is going to have. The elements need to be added to the array dynamically. I looked at the NSArray class reference. There is a method called…
saikamesh
  • 4,569
  • 11
  • 53
  • 93
41
votes
6 answers

How do I add a CGPoint to NSMutableArray?

I want to store my CGPoint to the NSMutable Array, so , I have method like this: [self.points addObject:CGPointMake(x, y)]; But I got the error, it said that : Incompatible type for argument 1 of "addObject". So, I check out the API, -…
Tattat
  • 15,548
  • 33
  • 87
  • 138
40
votes
6 answers

iOS - Map a root JSON array with ObjectMapper in swift

I use the library ObjectMapper to map json with my objects but I have some issues to map a root json Array. This is the received json : [ { CustomerId = "A000015", ... }, { CustomerId = "A000016", ... }, { …
Nicolas HENAUX
  • 1,656
  • 1
  • 14
  • 18
40
votes
5 answers

Testing if NSMutableArray contains a string object

I have a NSMutableArray which contains a few NSString objects. How can I test if the array contains a particular string literal? I tried [array containsObject:@"teststring"] but that doesn't work.
tech74
  • 1,355
  • 3
  • 21
  • 35
40
votes
5 answers

Store [String] in NSUserDefaults

I want to save a Swift Style String Array into NSUserDefaults, but acutally the "if" statement in the code says that returnValue is always nil. Later in the code (iOS 8) I want to use "food += ["spaghetti"] to add new entries. var food : [String] { …
Thomas
  • 1,468
  • 4
  • 14
  • 20
37
votes
3 answers

Executing Blocks From NSArray?

I was just thinking, as you can treat Blocks like objects if I create two of them and then add them to an NSArray is there a way to execute them from the array? int (^Block_001)(void) = ^{ return 101; }; int (^Block_002)(void) = ^{ return 202;…
fuzzygoat
  • 26,573
  • 48
  • 165
  • 294
36
votes
6 answers

How to replace an object in an NSMutableArray at a given index with a new object

I have an NSMutableArray object (retained, synthesized as all) that is initiated just fine and I can easily add objects to it using the addObject: method. But if I want to replace an object at a certain index with a new one in that NSMutableArray,…
user339076
  • 431
  • 2
  • 5
  • 4
36
votes
2 answers

Using NSPredicate to determine if a string equals another string

I have an NSArray of CalEvents returned with the [CalCalendarStore eventPredicateWithStartDate] method. From the events returned, I am trying to keep only those in which the title of the event == @"on call" (case-insensitive). I am able to keep in…
Garry Pettet
  • 8,096
  • 22
  • 65
  • 103
36
votes
13 answers

How do I get a list of countries in Swift ios?

I've already seen two similar questions to mine, but the answers for those questions do not work for me. I have an old project with a list of countries manually typed out inside a set of square brackets. I can easily use this in my pickerView but…
LondonGuy
  • 10,778
  • 11
  • 79
  • 151