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
Filter by
Sorted by
Tagged with
1325 votes
27 answers
486k views

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 ...
rustyshelf's user avatar
394 votes
9 answers
208k views

How do I convert NSMutableArray to NSArray?

How do I convert NSMutableArray to NSArray in objective-c?
marcy's user avatar
  • 4,223
152 votes
14 answers
107k views

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's user avatar
131 votes
3 answers
54k views

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's user avatar
  • 43.7k
114 votes
4 answers
27k views

How to store CGRect values in NSMutableArray?

How would I store CGRect objects in a NSMutableArray, and then later retrieve them?
Krishna Chaitanya Bandaru's user avatar
106 votes
3 answers
66k views

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 ...
node ninja's user avatar
  • 32.3k
92 votes
3 answers
93k views

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's user avatar
  • 29.6k
84 votes
5 answers
131k views

'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 ...
user3085646's user avatar
  • 1,035
69 votes
9 answers
55k views

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, ...
Zak's user avatar
  • 12.4k
69 votes
12 answers
55k views

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 @...
Tuyen Nguyen's user avatar
  • 4,399
67 votes
4 answers
40k views

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's user avatar
  • 6,283
67 votes
9 answers
83k views

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 ...
user2841148's user avatar
66 votes
8 answers
70k views

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 ...
fuzzygoat's user avatar
  • 26.1k
63 votes
3 answers
26k views

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 ...
James P. Wright's user avatar
62 votes
3 answers
45k views

Difference between NSArray and NSMutableArray

What is the difference b/w NSArray and NSMutableArray?
g.revolution's user avatar
  • 12.1k
59 votes
2 answers
68k views

NSMutableArray addObject not working

I have declared an NSMutableArray *categories in my view controller .h file, and declared a property for it. In the parser:foundCharacters: method of the NSXMLParser delegate in my .m file, I have ...
joec's user avatar
  • 3,543
58 votes
5 answers
16k views

Is there a literal syntax for mutable collections?

I know I can create an NSArray with @[@"foo", @"bar"] or an NSDictionary with @{@0 : @"foo", @1 : @"bar"}. Is there a literal syntax for creating an NSMutableArray or an NSMutableDictionary?
ma11hew28's user avatar
  • 124k
56 votes
1 answer
16k views

Swapping elements in an NSMutableArray

Are there any special methods to make swapping elements in an NSMutableArray easier or more direct?
node ninja's user avatar
  • 32.3k
55 votes
3 answers
19k views

NSMutableArray add object with order

I have a NSMUtableArray which has elements, for example: a,b,c,e And I want to add an object d to behind c and before e. In other words, I'd like to insert an object to a sorted array.(The object ...
scorpiozj's user avatar
  • 2,687
54 votes
9 answers
49k views

how to add nil to nsmutablearray?

NSArray *array = [[NSArray alloc] initWithObjects:@"ΕΛΤΑ", @"ΕΛΤΑ COURIER", @"ACS", @"ACS ΕΞΩΤΕΡΙΚΟ", @"DHL", @"INTERATTICA", @"SPEEDEX", ...
stefanosn's user avatar
  • 3,304
54 votes
7 answers
35k views

Is Objective-C's NSMutableArray thread-safe?

I've been trying to fix this crash for almost a week. The application crashes without any exception or stack-trace. The application does not crash in any way while running through instruments in ...
aryaxt's user avatar
  • 77k
50 votes
9 answers
49k views

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 ...
Alexander Farber's user avatar
50 votes
2 answers
29k views

Add an object to the beginning of an NSMutableArray?

Is there an efficient way to add an object to start of an NSMutableArray? I am looking for a good double ended queue in objective C would work as well.
gurooj's user avatar
  • 2,100
46 votes
11 answers
54k views

Avoiding "NSArray was mutated while being enumerated"

I have an NSMutableArray that stores mousejoints for a Box2d physics simulation. When using more than one finger to play I'll get exceptions stating NSArray was mutated while being enumerated I ...
glenstorey's user avatar
  • 5,134
45 votes
9 answers
80k views

NSMutableArray check if object already exists

I am not sure how to go about this. I have an NSMutableArray (addList) which holds all the items to be added to my datasource NSMutableArray. I now want to check if the object to be added from the ...
Neelesh's user avatar
  • 3,693
45 votes
8 answers
57k views

2D arrays using NSMutableArray

I need to create a mutable two-dimensional array in Objective-C. For example I have: NSMutableArray *sections; NSMutableArray *rows; Each item in sections consists of an array rows. rows is an ...
Ilya Suzdalnitski's user avatar
44 votes
2 answers
19k views

Sorting NSMutableArray By Object's Property

So this is a rather basic question regarding the best way to sort an NSMutableArray of custom objects. I have a an NSMutableArray of custom objects, each object with an NSString and NSDate that go ...
Rich Haygren's user avatar
42 votes
7 answers
25k views

Reverse NSMutableArray

What is the best/correct way to reverse an NSMutableArray?
some_id's user avatar
  • 29.6k
42 votes
4 answers
38k views

How can I sort strings in NSMutableArray into alphabetical order?

I have a list of strings in an NSMutableArray, and I want to sort them into alphabetical order before displaying them in my table view. How can I do that?
praveena's user avatar
  • 733
41 votes
3 answers
20k views

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 ...
GeneCode's user avatar
  • 7,540
41 votes
3 answers
96k views

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 ...
user440485's user avatar
40 votes
5 answers
25k views

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 ...
Dharmesh Kheni's user avatar
40 votes
5 answers
19k views

Finding Intersection of NSMutableArrays

I have three NSMutableArray containing names that are added to the lists according to different criterieas. Here are my arrays pseudocode: NSMutableArray *array1 = [@"Jack", @"John", @"Daniel", @"...
aeciftci's user avatar
  • 679
39 votes
5 answers
74k views

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 ...
user avatar
37 votes
1 answer
34k views

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

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(@"...
Sam Jarman's user avatar
  • 7,327
35 votes
4 answers
52k views

[__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 '...
lhencq's user avatar
  • 505
35 votes
5 answers
41k views

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 ...
anthoprotic's user avatar
34 votes
5 answers
19k views

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's user avatar
  • 7,517
33 votes
5 answers
13k views

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 ...
igul222's user avatar
  • 8,607
32 votes
1 answer
37k views

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's user avatar
  • 32.3k
31 votes
3 answers
51k views

Converting NSArray to NSMutableArray [closed]

As above. Would be helpful to know. Thanks!
Sidwyn Koh's user avatar
  • 1,742
31 votes
6 answers
85k views

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"]; ...
SamBo's user avatar
  • 551
30 votes
5 answers
25k views

Sort array of objects by their NSDate property [duplicate]

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 ...
some_id's user avatar
  • 29.6k
28 votes
3 answers
63k views

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 ...
babyDeveloper's user avatar
26 votes
2 answers
9k views

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 ...
Joey's user avatar
  • 7,537
25 votes
7 answers
42k views

How can I sort an NSMutableArray alphabetically?

I want to sort an NSMutableArray alphabetically.
Ali's user avatar
  • 11.1k
25 votes
7 answers
55k views

Removing item from array by property value

I'm looking for the most efficient and memory friendly way. Let's say I have an array of Person objects. Each person has a hair color represented by an NSString. Let's then say I want to remove all ...
Choppin Broccoli's user avatar
24 votes
4 answers
21k views

NSMutableArray - Remove duplicates

i tried doing this: Values = [[NSSet setWithArray:Values] allObjects]; and no sucess, Thanks
user393273's user avatar
  • 1,440
24 votes
4 answers
34k views

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

How to check an NSMutableArray is null or not ?
S.P.'s user avatar
  • 5,435
24 votes
3 answers
61k views

How to addObject of NSMutableDictionary to NSMutableArray in a loop

I'm having difficulty to add a data structure to an array to create an array of dictionaries from a loop. I just knew that addObject in NSMutableArray only add pointer to it. I would like to know how ...
Ber Biji II's user avatar

1
2 3 4 5
107