我有一个NSNumber
s 数组,例如:10015,12313,10016
我想检查数组是否包含我在searchBar中输入的整数.
我的代码:
NSPredicate *resultPredicate = [NSPredicate
predicateWithFormat:@"SELF CONTAINS[c] %d", [searchText intValue]];
self.searchResults = [newArr filteredArrayUsingPredicate:resultPredicate];
Run Code Online (Sandbox Code Playgroud) 我在iOS应用程序中使用parse.com将数据存储到解析云服务.我遇到了嵌套对象查询的问题.我有以下数据模型:
"游戏"类包含"获胜者"
"获胜者"是一个数组NSDictionary
,字典中的每个项目都是1个玩家到N个人的映射
playerPowers值是一个PFObjects数组(当前只有一个名称的权力)key:objectId of a player(PFObject)
对于每个获胜者,我向"赢家"(可能有多个获胜者)添加一个NSDictionary
对象,如下所示:
NSDictionary * winnerWithPowers = [NSDictionary dictionaryWithObject:tempPowers
forKey:[aWinnerPFObject objectId]];
[newGame addObject:winnerWithPowers forKey:@"winners"];
Run Code Online (Sandbox Code Playgroud)
对于字典中的每个项目,键是播放器的现有objectId,值PFObjects
也是服务器上的(幂)数组.当我查询"获胜者"时,我想要检索所有填充的数据,所有获胜者及其各自的权力PFObjects
及其所有数据.当我查询"获胜者"时,每个权力的细节PFObject
都是不完整的(键的值:名称为空).以下是查询,然后是打印结果的代码,然后输出包含两个获胜者的字典:
//在viewWillAppear中:
PFQuery * gamesQuery = [PFQuery queryWithClassName:@"Game"];
[gamesQuery orderByDescending:@"createdAt"];
[gamesQuery findObjectsInBackgroundWithBlock:^(NSArray * theGames, NSError * error) {
if (error) {
NSLog(@"ERROR: There was an error with the Query for Games!");
} else {
_gamesPF = [[NSMutableArray alloc] initWithArray:theGames];
[_tableView reloadData];
}
}];
Run Code Online (Sandbox Code Playgroud)
//在tableview中的cellForRowAtIndexPath: …