gpt4 book ai didi

ios - Thread1v :signal SIGABRT

转载 作者:行者123 更新时间:2023-11-28 21:50:47 26 4
gpt4 key购买 nike

我是Android Developer,现在正在转IOS,所以我是IOS开发新手。我在这个地方出错了

Thread1v:signal SIGABRT 。如何解决错误

 -(void)updatePostCountUserDefaults{

NSMutableDictionary *postCount ;

NSNumber *count;

if([[NSUserDefaults standardUserDefaults] objectForKey:@"postCount"] !=nil){

postCount = [[NSUserDefaults standardUserDefaults] objectForKey:@"postCount"];

count = [postCount objectForKey:@"count"];

count = [NSNumber numberWithInt:([count integerValue] + 1.0)];

int n = [count integerValue];

NSLog(@"hey count is : %i" , n);

[postCount setObject:count forKey:@"count"];

}else{

postCount = [[NSMutableDictionary alloc] init];

count = [NSNumber numberWithInt:1];

[postCount setObject:count forKey:@"count"]; //error-

}

[[NSUserDefaults standardUserDefaults] setObject:postCount forKey:@"postCount"];

[[NSUserDefaults standardUserDefaults] synchronize];
int num = [count integerValue];
NSLog(@"count is %i " , num);
if([count integerValue] == 4 || [count integerValue] == 12){
// show rating screen

}

请帮忙

最佳答案

实际上我认为您标记为“错误”的行不会崩溃。它 [postCount setObject:count forKey:@"count"]; 会导致异常。因为 postCount 在该上下文中是一个 NSDictionary,而不是一个可变字典。因此,它无法响应 setObject:forKey:

编辑:正确的代码:

if([[NSUserDefaults standardUserDefaults] objectForKey:@"postCount"] !=nil){
postCount = [[[NSUserDefaults standardUserDefaults] objectForKey:@"postCount"] mutableCopy];
count = [postCount objectForKey:@"count"];
count = [NSNumber numberWithInt:([count integerValue] + 1.0)];
int n = [count integerValue];
NSLog(@"hey count is : %i" , n);
[postCount setObject:count forKey:@"count"];
}else{...}

关于ios - Thread1v :signal SIGABRT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28431174/

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