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
39
votes
3 answers

How to wrap a Struct into NSObject

this is supposed to be trivial… I think, but I can't find a way how to wrap a Struct variable into an NSObject. Is there a method to do so? If not, how would I go about adding a struct into an NSMutableArray? Thanks.
GeneCode
  • 7,148
  • 7
  • 42
  • 75
38
votes
5 answers

Total Size of NSMutableArray object

I've got an NSMutableArray that holds a bunch of objects, what I'm trying to figure out is how much memory is the array using. After looking at a couple of places I know about the size of call, and when I make it I get 32 bits (which is the size of…
sj wengi
37
votes
5 answers

How to exchange elements in swift array?

I have one simple array like: var cellOrder = [1,2,3,4] I want to exchange elements like suppose a second element with first element. And result will be: [2,1,3,4] I know we can use exchangeObjectAtIndex with NSMutableArray But I want to use swift…
Dharmesh Kheni
  • 67,254
  • 32
  • 154
  • 160
37
votes
1 answer

How do I reverse the order of objects in an NSMutableArray?

I'm trying to achieve something like this NSMutableArray *myArray = [NSMutableArray arrayWithObjects:@"A",@"B",@"C", nil]; NSLog(@"Array: %@", myArray); //logs A, B, C. //reverse code here NSLog(@"Array: %@", myArray); //logs C, B, A The code…
Sam Jarman
  • 7,025
  • 14
  • 49
  • 98
34
votes
3 answers

How to append values to an array in Objective-C

I'm doing this: for(int i=0;i>count;i++) { NSArray *temp=[[NSArray alloc]initWIthObjects]i,nil]; NSLog(@"%i",temp); } It returns to me 0,1,2,3....counting one by one, but I want an array with appending these values {0,1,2,3,4,5...}. This is…
user440485
  • 727
  • 2
  • 11
  • 20
34
votes
5 answers

UIActivityViewController - Email and Twitter sharing

I recently started working with UIActivity to share my app to the world, but I have few problems. First, I didn't find how to set the subject of my email. Is there any way? Second, when I set the body text of my email, there is a extra "enter"…
anthoprotic
  • 817
  • 2
  • 12
  • 24
33
votes
4 answers

[__NSCFNumber length]: unrecognized selector sent to instance UITableView

i'm experiencing an error [__NSCFNumber length]: unrecognized selector sent to instance 0x15580c90 2014-02-18 15:10:49.490 CIB[1706:60b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber length]:…
lhencq
  • 485
  • 2
  • 6
  • 15
33
votes
5 answers

Disadvantage of using NSMutableArray vs NSArray?

I'm using an array to store cached objects loaded from a database in my iPhone app, and was wondering: are there any significant disadvantages to using NSMutableArray that I should know of? edit: I know that NSMutableArray can be modified, but I'm…
igul222
  • 8,327
  • 14
  • 47
  • 58
32
votes
5 answers

How to sort an array which contains Dictionaries?

I have an array which contains dictionaries in it; so how can I sort the array according to dictionary key values?
Ankit Vyas
  • 7,401
  • 13
  • 52
  • 87
31
votes
1 answer

How to change the value of an NSMutableArray at a particular index

[array objectAtIndex:i] doesn't work as an L value, so it can't be used to set the object at index i.
node ninja
  • 28,340
  • 55
  • 153
  • 242
31
votes
3 answers

Converting NSArray to NSMutableArray

As above. Would be helpful to know. Thanks!
Sidwyn Koh
  • 1,702
  • 2
  • 21
  • 29
30
votes
5 answers

Sort array of objects by their NSDate property

Possible Duplicate: How to sort an NSMutableArray with custom objects in it? How does one sort an array of objects by accessing their NSDate properties? I know one can use [mutableArray sortUsingSelector:@selector(compare:)]; on an array of…
some_id
  • 28,294
  • 58
  • 173
  • 293
28
votes
3 answers

How to sort NSMutableArray using sortedArrayUsingDescriptors?

I have a question about sorting NSMutableArray. I can use sortedArrayUsingDescriptors: method to sort an array with objects. For example I have an NSMutableArray of places where I have an attribute frequency (int value) and I want to sort…
babyDeveloper
  • 281
  • 1
  • 3
  • 4
28
votes
6 answers

How to add string objects to NSMutableArray

I have an NSMutableArray named randomSelection: NSMutableArray *randomSelection; I am then trying to add strings to this array if certain criteria are met: [randomSelection addObject:@"string1"]; I am then trying to output the string, to determine…
SamBo
  • 521
  • 2
  • 6
  • 13
26
votes
2 answers

NSMutableArray initWithCapacity nuances

Does anyone have advice on how to best initialize an NSMutableArray when it comes to dictating the capacity? The documentation mentions that "...even though you specify a size when you create an array, the specified size is regarded as a “hint”;…
Joey
  • 7,457
  • 12
  • 50
  • 103