gpt4 book ai didi

ios - NSMutableArray 保存和加载到默认值无法正常工作

转载 作者:行者123 更新时间:2023-11-29 03:06:54 25 4
gpt4 key购买 nike

已解决 这是我的错,我有另一个 if 阻止了方法调用。对不起。

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.

最佳答案

使用objectForKey而不是arrayForKey:

NSArray *array=[defaults objectForKey:@"arenaszavakosszes"];

关于ios - NSMutableArray 保存和加载到默认值无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22669323/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com