为什么我收到此问题错误?
指向整数转换的指针不兼容发送' NSArray * __ strong'到#NSUInteger'
类型的参数#import "FSConverter.h"
#import "FSVenue.h"
@implementation FSConverter
- (NSArray *)convertToObjects:(NSArray *)venues {
NSMutableArray *objects = [NSMutableArray arrayWithCapacity:venues];
for (NSDictionary *v in venues) {
FSVenue *ann = [[FSVenue alloc]init];
ann.name = v[@"name"];
ann.venueId = v[@"id"];
ann.location.address = v[@"location"][@"address"];
ann.location.distance = v[@"location"][@"distance"];
[ann.location setCoordinate:CLLocationCoordinate2DMake([v[@"location"][@"lat"] doubleValue],
[v[@"location"][@"lng"] doubleValue])];
[objects addObject:ann];
}
return objects;
}
@end
错误在这一行:
NSMutableArray *objects = [NSMutableArray arrayWithCapacity:venues];
答案 0 :(得分:1)
因为[NSMutableArray arrayWithCapacity:]
需要一个整数而不是一个数组作为参数。
假设您要创建一个与传入的数组具有相同初始容量的可变数组,那么您可能意味着:
NSMutableArray *objects = [NSMutableArray arrayWithCapacity:venues.count];
或简单地说:
NSMutableArray *objects = [NSMutableArray new];
(如果您使用的是[objects addObject:]
),请忘记初始容量。