gpt4 book ai didi

ios - 'NSDictionary' 方法 'dictionaryWithObjectsAndKeys:' 的参数应该是 Objective-C 指针类型,而不是 int

转载 作者:行者123 更新时间:2023-11-28 22:00:51 24 4
gpt4 key购买 nike

-(NSMutableArray*)getLSBGoalList
{
int userId = [[[AppManager sharedAppManager].userInfo objectForKey:USER_ID] intValue];

NSString *query = [NSString stringWithFormat:@"SELECT * FROM tblLBGoal WHERE userId = %d ORDER BY groupId", userId];

FMResultSet *rs = [database executeQuery:query];
NSMutableArray *arrLSBGoals = [NSMutableArray array];
while([rs next])
{
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:[rs intForColumn:@"lbGoalId"]], @"lbGoalId",
[NSNumber numberWithInt:[rs intForColumn:@"groupId"]], @"groupId",
[NSNumber numberWithInt:[rs intForColumn:@"userId"]], @"userId",
[rs stringForColumn:@"uuid"],@"uuid",
[NSNumber numberWithInt:[rs intForColumn:@"dataSyncType"]], @"dataSyncType",
[NSNumber numberWithInt:[rs intForColumn:@"idealValue"]], @"idealValue",
[NSNumber numberWithInt:[rs intForColumn:@"targetValue"]], @"targetValue",nil,
[NSNumber numberWithInt:[rs intForColumn:@"isTargetSet"]], @"isTargetSet",nil];

[arrLSBGoals addObject:dict];
}
return arrLSBGoals;
}

我正在使用上面的代码,当我分析我的项目时,我收到一条警告,“NSDictionary”方法“dictionaryWithObjectsAndKeys:”的参数应该是一个 objective-C 指针类型,而不是 int。 Analyzer 向我展示了以下修复方法,但我不明白该怎么做。谁能帮帮我。 enter image description here

最佳答案

你在最后一行中有一个额外的nil:

[NSNumber numberWithInt:[rs intForColumn:@"targetValue"]], @"targetValue",nil,  // here
[NSNumber numberWithInt:[rs intForColumn:@"isTargetSet"]], @"isTargetSet",nil];

使用较新的 Objective-C 字典字面量语法更易于阅读,并且不需要终止 nil:

NSDictionary *dict = @{
@"lbGoalId" : @([rs intForColumn:@"lbGoalId"]),
@"groupId" : @([rs intForColumn:@"groupId"]),
// etc.
};

关于ios - 'NSDictionary' 方法 'dictionaryWithObjectsAndKeys:' 的参数应该是 Objective-C 指针类型,而不是 int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25135295/

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