Sunday, 15 April 2012

iphone - adding a custom class object to array -



iphone - adding a custom class object to array -

i seek add together custom object class created nsuserdefaults array stays empty. log i'm getting is:

"note dictionaries , arrays in property lists must contain property values"

my code is:

-(void)addprogramwithname:(nsstring *)nameofprogram andwitharrayofintervals:(nsmutablearray *)arrayofintervals{ programme *tempprogram = [[program alloc] init]; tempprogram.nameofprogram = nameofprogram; tempprogram.arrayofintervals = arrayofintervals; nsmutablearray *temparrayofprograms = [nsmutablearray arraywitharray: [[nsuserdefaults standarduserdefaults] arrayforkey: @"arrayofprograms"]]; [temparrayofprograms addobject:tempprogram]; [defaults setobject:temparrayofprograms forkey:@"arrayofprograms"]; [defaults synchronize]; }

what may reason be?

the reason problem log message says - property list, object add together array (or dictionary) must property value (strings, numbers, dates , arrays/dictionaries thereof).

so in case seems have read in values user defaults, , want add together custom objects values have read in.

if don't intend write amended array out user defaults, there nil wrong approach (although strikes me gung-ho approach info structures).

on other hand, if need write info back, should store property values in array. more complex objects, can accomplished encoding in dictionary object keys , values.

depending on needs, core info might more suited data, though.

iphone xcode

No comments:

Post a Comment