0
votes

I have a NSMutableArray I get by loading a plist into it. The date field comes in as a string and i want to change it into a nsdate. I can change an nsstring into an nsdate.

My array is an array of objects like the one below;

{
Date = "1/1/2009"
Description = "Have you ever looked at a badger and thought i wonder how far you could fire that out of a cannon? Well this talk is for you";
File = "http://www.badgerCannon.org.uk/mp3/070310pm.mp3";
Series = "The Badger planet";
Speaker = "Will Ferell";
Title = "Is it a bird, is it a plane? no its a badger";
}

I loop through and pull out the date and convert it from a NSString to a NSDate.

I try writing it back in using the code;

[[self.MediaDataArray objectAtIndex:i] replaceObjectAtIndex:0 withObject:Date];

but it errors and i am pretty sure it is because i am not putting it back into the array in the same format, ie just as a date not as date = "date". But lets face it i don't really know!

Am i barking up the wrong tree? Please help, i have got the coding equivalent of writters block, or alternatively am just being really stupid! thanks in advance

1
You say that you get an error, but you don't say what it is.Paul Lynch
Yes, you are barking up the wrong tree. An array does not care about the type of objects it contains. What error message do you get?Ole Begemann
2010-04-29 10:40:23.058 mediaLibrary[1406:207] *** -[NSCFDictionary replaceObjectAtIndex:withObject:]: unrecognized selector sent to instance 0x411beb0 2010-04-29 10:40:23.058 mediaLibrary[1406:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFDictionary replaceObjectAtIndex:withObject:]: unrecognized selector sent to instance 0x411beb0'padatronic

1 Answers

0
votes

The error message says it all: [self.MediaDataArray objectAtIndex:i] returns a NSDictionary, which obviously does not understand the replaceObjectAtIndex:withObject: message. You are confusing dictionaries and arrays.

First, make sure that the dictionary you are dealing with is a NSMutableDictionary. Then, change the code to:

[[self.MediaDataArray objectAtIndex:i] setObject:Date forKey:@"Date"];