Use objectForKey
instead of arrayForKey
:
NSArray *array=[defaults objectForKey:@"arenaszavakosszes"];
문제
SOLVED it was my bad, i had another if which blocked the method calling. Sorry.
i have problem saving and loading an NSMutableArray to the NSUSerDefaults. Im going to copy the whole code here, its 2 function. i Think there is some problems with the savving.
+(NSArray*)getarenawordsarraywithcheck{ NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults]; NSArray *array=[defaults arrayForKey:@"arenaszavakosszes"]; if ([array count]==0) { NSString *path=[[NSBundle mainBundle] pathForResource:@"arenawordsenglish" ofType:@"plist"]; array=[NSArray arrayWithContentsOfFile:path]; [defaults setObject:array forKey:@"arenaszavakosszes"]; [defaults synchronize]; } NSLog(@"Actual Size of the array:%i",[array count]); return array; } +(void) deletestringfromarenawordsandsaveforstring:(NSString*)actualword{ NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults]; NSMutableArray *array=[[defaults objectForKey:@"arenaszavakosszes"]mutableCopy] ; NSLog(@"Removing the words: %@ from the words actuall size of the array:%i",actualword,[array count]); [array removeObject:actualword]; [defaults setObject:array forKey:@"arenaszavakosszes"]; [defaults synchronize]; NSLog(@"Removed. New size of the array:%i",[array count]); }
UI: I tried to use even the [defaults mutableArrayValueForKey:@"arenaszavakosszes"]. The problem is, when I try to load the array in the second method it returns nil. Help please.
해결책
Use objectForKey
instead of arrayForKey
:
NSArray *array=[defaults objectForKey:@"arenaszavakosszes"];