nsmutablearray

Using sortUsingSelector on an NSMutableArray

I have used sortUsingSelector to sort an NSMutableArray of custom objects. Now I'm trying to sort an NSMutableArray containing NSMutableArrays of custom objects. Can you use sortUsingSelector on an NSMutableArray, or does it only work for custom classes? ...

Swapping elements in an NSMutableArray

Are there any special methods to make swapping elements in an NSMutableArray easier or more direct? ...

Conditionally populate an array from another array - objectiveC

I want to copy items from an array that are not 0 or @"" (depending if NSNumber or NSString). The following code, however, does not work. What am I doing wrong? for (int i=0; i < [logbookItems count]; i++) { NSLog(@"%@, %@, %@", [[[logbookItems objectAtIndex:i] objectAtIndex:1] class], [[logbookItems objectAtIndex:i] objectAtIndex:0...

Return error in NSMutableArray

I'm trying to to return a NSMutableArray but I got this error in the console: 2010-10-01 14:12:21.348 Phonebook[1424:a0f] +[LinkedList getListArray]: unrecognized selector sent to class 0x1000053e8 The method code is: - (id)getListArray { ListNode *tmp = iterator; iterator = head; NSMutableArray * list = [NSMutableArray...

Error adding object to mutable array

for (NSString *CurrentArtistName in ArtistNamesArray) { CurrentArtistName = [CurrentArtistName stringByMatching:regEx capture:1]; NSLog(CurrentArtistName); [ArtistNames addObject: CurrentArtistName]; } why is this closing my app ? There are no errors in the coding and the NSLog is logging the CurrentArtistName ? i really ...

Sorting an NSMutableArray containing matching "pairs" of values.

I'd prefer not to change the way anArray is designed because it is also used elsewhere as a dataSource for a UITableView. The odd number values are "user names", and the even number values are their matching "dates". (The "pairs" must remain together.) How would I sort "by user name"? How would I sort "by date"? Should I be using s...

How to sort an array of objects by their NSString property

I have an array of custom objects. One of the properties of these objects is an NSString. I want to sort by that property. Because it is an NSString and not an NSNumber sorting is a little more difficult. Is there some kind of class method to help in this case? How should it be done? ...

How should I fix this code?

I'm trying to sort an array of people objects. The class looks like this. Person ------- name phone I have an NSMutableArray filled with these objects. I want to sort this array by the name of each person object. This is the code I tried. NSSortDescriptor *desc = [[NSSortDescriptor alloc] initWithKey: @"name" ascending: YES]; [pers...

How to store Fetch results in Application's plist file?

I'm querying rows from my sqlite database using Fetch and loading the results into a NSMutableArray myDataArray. What I want to do is to store the values in myDataArray into my application's preferences plist file. But when I run the code below I get the following error: [NSUserDefaults setObject:forKey:]: Attempt to insert non-property...

How to remove all objects from a NSMutable Array ?

Hi all, I need to remove all objects from a NSMutable Array. I can't seem to do this by enumerating as the code crashes. Can anyone tell me the best way to do this with code example if possible ? Many thanks, Martin ...

Should I subclass the NSMutableArray class

I have an NSMutableArray object that I want to add custom methods to. I tried subclassing NSMutableArray but then I get an error saying "method only defined for abstract class" when trying to get the number of objects with the count method. Why is the count method not inherited? I read somewhere else that I will have to import some NSMu...

How to sort this NSMutableArray?

I made a class called Person. It looks like this Person ------- Name Points Then I created an NSMutableArray called team. It contains several of these person objects. I create several teams. Then I created another NSMutableArray called allTeams. It holds all the team arrays. I want to sort the allTeams array by the total number of p...

How to change this code so the NSMutableArray is sorted?

I made a custom class. This is the h file @interface Player : NSObject { NSString *name; NSNumber *points; } @property (nonatomic, retain) NSString *name; @property (nonatomic, retain) NSNumber *points; -(id) initWithName:(NSString *)n andPoints:(int)p; @end This is the m file #import "Player.h" @implementation Player @sy...

Remove duplicates nsmutableArray

i tried doign this: Values = [[NSSet setWithArray:Values] allObjects]; and no sucess, Thanks ...

Object changes from NSMutableArray to NSData to NSString

I have a program which works normally. Then I downloaded some code from http://github.com/matej/MBProgressHUD to show a progress meter when doing something. This is the code that makes the progress meter pop up. [HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES]; This will show a progress meter while...

iPhone NSMutableArray and NSKeyedUnarchiver unarchiveObjectWithFile release oddity

I archive an array (NSMutableArray) of custom objects that implement the . Once i load it froma file to a retaining property @property (nonatomic, retain) NSMutableArray *buddies; the release count of the object is 2 (correct, it's 1of autorelease + 1 of retain of the property) but then noone releases it and the retain count becames 1, ...

NSMutableArray causing EXC_BAD_ACCESS crash after viewcontroller did disappear and re appears

Still "somewhat" of a newbie... I have an NSMutableArray that stores filenames - when a user clicks a UITableView the corresponding selected cell will pass the certain filename in the array to MPMoviePlayerController to play. It works, however if I exit out of the viewcontroller and come back, only the last video that I played will work,...

Editing one object in an NSMutableArray also changes another object in the NSMutableArray

I had a navigation application that was working normally. In the table view, the last item is called "add item", and if the user pressed it, it would create a new object and pass it to another view where the user could enter the details for that object. When the user returned to the previous screen, the new object would show in the array...

How to make a copy of a custom object

I made a custom object that inherits from NSObject. Let's say I have an array of these objects. Then I want to make another object, that is a copy of one of the objects in the array. I do not want to simply point to an existing object in the array I want a copy. Is there an easy way to do this? ...

How to prevent counting an empty NSMutableArray

Hi, I would like to simulate the SMS Bubbles of the iPhone for my own app. I found some nice code overhere (FYI): http://vimeo.com/8718829 . It is a restyled UITableView. Exactly what a wanted. Here is the problem: - The Tableview is filled with an array of messages - It needs to be a NSMutable array because you want to add messages on...