gpt4 book ai didi

iphone - NSMutableDictionary上的EXC_BAD_ACCESS

转载 作者:行者123 更新时间:2023-12-01 17:57:28 26 4
gpt4 key购买 nike

我从iOS开发开始,我有以下代码:

首先,我声明listOfItems NSMutableArray:

@interface SAMasterViewController () {
NSMutableArray *listOfItems;
}
@end

现在,这是给我“EXC_BAD_ACCESS(代码= 1,地址= 0x5fc260000)”错误的代码。
该错误在“individual_data”对象的最后一行给出。
listOfItems = [[NSMutableArray alloc] init];
for(NSDictionary *tweetDict in statuses) {
NSString *text = [tweetDict objectForKey:@"text"];
NSString *screenName = [[tweetDict objectForKey:@"user"] objectForKey:@"screen_name"];
NSString *img_url = [[tweetDict objectForKey:@"user"] objectForKey:@"profile_image_url"];
NSInteger unique_id = [[tweetDict objectForKey:@"id"] intValue];
NSInteger user_id = [[[tweetDict objectForKey:@"user"] objectForKey:@"id"] intValue ];

NSMutableDictionary *individual_data = [NSMutableDictionary dictionaryWithObjectsAndKeys:
text, @"text_tweet",
screenName,@"user_name",
img_url, @"img_url",
unique_id, @"unique_id",
user_id, @"user_id", nil];
[listOfItems addObject:individual_data];
}

提前致谢。

最佳答案

您不能将NSInteger或任何其他非Objective-C类放入数组或字典中。您需要将它们包装在 NSNumber 中。

NSMutableDictionary *individual_data = [NSMutableDictionary dictionaryWithObjectsAndKeys:
text, @"text_tweet",
screenName,@"user_name",
img_url, @"img_url",
[NSNumber numberWithInteger:unique_id], @"unique_id",
[NSNumber numberWithInteger:user_id], @"user_id", nil];
//Or if you want to use literals
NSMutableDictionary *individual_data = [NSMutableDictionary dictionaryWithObjectsAndKeys:
text, @"text_tweet",
screenName,@"user_name",
img_url, @"img_url",
@(unique_id), @"unique_id",
@(user_id), @"user_id", nil];

关于iphone - NSMutableDictionary上的EXC_BAD_ACCESS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14663446/

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