[英]How to access an nsarray count in a special case
I have block set up as follows: 我将块设置如下:
id block = ^(id obj, BOOL *ignored)
{
id data = [self.writer dataWithObject:obj];
NSString *output = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
};
When i do the call: 当我打电话时:
[[obj objectForKey:@"roster] objectForKey:@"players"];
I am looking at an array of players. 我在看各种各样的球员。 When I add .count, it cannot find a count because it says count is not a property of id. 当我添加.count时,它找不到计数,因为它说count不是id的属性。 How can I access the count of this array? 如何访问此数组的计数?
Edit: 编辑:
This is my full block: 这是我的全部内容:
id block = ^(id obj, BOOL *ignored) {
id data = [self.writer dataWithObject:obj];
NSMutableArray *players = (NSMutableArray*)[[obj objectForKey:@"roster"] objectForKey:@"players"];
_players = [NSMutableArray array];
//Create player objects then add them to the array.
for (int i = 0; i <= players.count; i++)
{
[_players addObject:[HNPlayerObject newPlayerWithPlayerId:(@"%@",[[[obj objectForKey:@"roster"] objectForKey:@"players"][i] objectForKey:@"id"])FirstName:(@"%@",[[[obj objectForKey:@"roster"] objectForKey:@"players"][i] objectForKey:@"first"]) LastName:(@"%@",[[[obj objectForKey:@"roster"] objectForKey:@"players"][i] objectForKey:@"last"]) Number:[(@"%@",[[[obj objectForKey:@"roster"] objectForKey:@"players"][i] objectForKey:@"number"]) intValue] Team:@"Badgers" Position:@"Unknown" Description:@"" GamesPlayed:[(@"%@",[[[obj objectForKey:@"roster"] objectForKey:@"players"][i] objectForKey:@"gp"]) intValue] Goals:[(@"%@",[[[obj objectForKey:@"roster"] objectForKey:@"players"][i] objectForKey:@"g"]) intValue] Assists:[(@"%@",[[[obj objectForKey:@"roster"] objectForKey:@"players"][i] objectForKey:@"a"]) intValue] Points:[(@"%@",[[[obj objectForKey:@"roster"] objectForKey:@"players"][i] objectForKey:@"pts"]) intValue] PenaltyMinutes:[(@"%@",[[[obj objectForKey:@"roster"] objectForKey:@"players"][i] objectForKey:@"pim"]) intValue] PlusMinus:[(@"%@",[[[obj objectForKey:@"roster"] objectForKey:@"players"][i] objectForKey:@"pm"]) intValue] IsPlaying:NO]];
[_playersTableView reloadData];
}
[_playersTableView reloadData];
};
I am getting this error: 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 17 beyond bounds [0 .. 16]' 我收到此错误:'NSRangeException',原因:'***-[__ NSArrayM objectAtIndex:]:索引17超出范围[0 .. 16]
NSArray *array = (NSArray*)[[obj objectForKey:@"roster] objectForKey:@"players"];
然后,您将可以访问count属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.