开发者

convert string to date and write back into NSMutableArray

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 pu开发者_StackOverflowtting 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


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"];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜