Questions tagged [nsmutablearray]

NSMutableArray represents a modifiable (mutable) array object for Cocoa and Cocoa Touch. It is Available in OS X v10.0 and later

NSMutableArray represents a modifiable (mutable) array object for Cocoa and Cocoa Touch. Its immutable variant is NSArray (), which is more efficient for memory and thread-safe than the mutable variant.

NSMutableArray represents a modifiable (mutable) array object for Cocoa and Cocoa Touch.

The NSMutableArray class declares the programmatic interface to objects that manage a modifiable array of objects and “toll-free bridged” with its Core Foundation.

The reason to subclass NSMutableArray from NSArray is this class does well what it is designed to do—maintain a mutable, ordered collection of objects. But there are situations where a custom NSArray object might come in handy.

Resources:

Question on NSMutableArray:

1.objective C: use NSMutableArray in different classes

2.How to sort an NSMutableArray with custom objects in it?

3.How do I convert NSMutableArray to NSArray?

Examples:

Creating Mutable Arrays

5318 questions
1290
votes
27 answers

How do I sort an NSMutableArray with custom objects in it?

What I want to do seems pretty simple, but I can't find any answers on the web. I have an NSMutableArray of objects, and let's say they are 'Person' objects. I want to sort the NSMutableArray by Person.birthDate which is an NSDate. I think it has…
rustyshelf
  • 44,085
  • 36
  • 96
  • 104
387
votes
9 answers

How do I convert NSMutableArray to NSArray?

How do I convert NSMutableArray to NSArray in objective-c?
marcy
  • 4,157
  • 3
  • 20
  • 14
150
votes
14 answers

The best way to remove duplicate values from NSMutableArray in Objective-C?

The best way to remove duplicate values (NSString) from NSMutableArray in Objective-C? Is this the easiest and right way to do it? uniquearray = [[NSSet setWithArray:yourarray] allObjects];
Teo Choong Ping
  • 11,262
  • 15
  • 61
  • 87
130
votes
3 answers

Join an Array in Objective-C

I'm looking for a method of turning a NSMutableArray into a string. Is there anything on a par with this Ruby array method? >> array1 = [1, 2, 3] >> array1.join(',') => "1,2,3" Cheers!
Codebeef
  • 41,810
  • 20
  • 83
  • 116
113
votes
4 answers

How to store CGRect values in NSMutableArray?

How would I store CGRect objects in a NSMutableArray, and then later retrieve them?
103
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
  • 28,340
  • 55
  • 153
  • 242
89
votes
3 answers

Adding an object at a specific index of an NSMutableArray

How can an object be added at a specific index of an NSMutableArray? How is an object added to the front of the array?
some_id
  • 28,294
  • 58
  • 173
  • 293
70
votes
4 answers

'Invalid update: invalid number of rows in section 0

I've read all of the related posts regarding this and I am still having an error: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (5) must be equal to the number of rows…
user3085646
  • 895
  • 2
  • 9
  • 14
68
votes
12 answers

NSMutableArray - force the array to hold specific object type only

Is there a way to force NSMutableArray to hold one specific object type only? I have classes definitions as follow: @interface Wheel:NSObject { int size; float diameter; } @end @interface Car:NSObject { NSString *model; …
Tuyen Nguyen
  • 4,159
  • 7
  • 45
  • 76
67
votes
9 answers

NSMutableArray addObject: -[__NSArrayI addObject:]: unrecognized selector sent to instance

I have tried to initialize my NSMutableArray 100 ways from Sunday, and NOTHING is working for me. I tried setting it equal to a newly allocated and initialized NSMutableArray, just allocating, initializing the variable by itself, every combination I…
Zak
  • 10,506
  • 15
  • 52
  • 90
67
votes
4 answers

Objective-C Simplest way to create comma separated string from an array of objects

So I have a nsmutablearray with a bunch of objects in it. I want to create a comma separated string of the id value of each object.
Jhorra
  • 5,873
  • 20
  • 65
  • 113
65
votes
8 answers

How do copy and mutableCopy apply to NSArray and NSMutableArray?

What is the difference between copy and mutableCopy when used on either an NSArray or an NSMutableArray? This is my understanding; is it correct? // ** NSArray ** NSArray *myArray_imu = [NSArray arrayWithObjects:@"abc", @"def", nil]; // No copy,…
fuzzygoat
  • 25,797
  • 45
  • 159
  • 288
63
votes
3 answers

UITableView, how do I know what Section during cellForRowAtIndexPath?

I have a UITableView displaying a list of Cities. I want to separate them by State. I can't seem to figure out how to get it to pick the right items out of my Array. If Section 1 (Arizona) has 2 Cities and Section 2 (California) has 2 Cities,…
James P. Wright
  • 8,663
  • 18
  • 72
  • 136
62
votes
9 answers

How to save NSMutablearray in NSUserDefaults

I have two NSMutableArray's. They consist of images or text. The arrays are displayed via a UITableView. When I kill the app the data within the UITableView gets lost. How to save array in UITableView by using NSUserDefault?
62
votes
3 answers

Difference between NSArray and NSMutableArray

What is the difference b/w NSArray and NSMutableArray?
g.revolution
  • 10,884
  • 19
  • 74
  • 102
1
2 3
99 100