Objective C Block Generics
我正在尝试实现一个数据源,可用于为tableview自定义几个不同类的单元格,但是我在传递给构造函数的块中遇到generics类型时遇到问题。
以下是数据源头文件的实现:
@interface ABParseDatasource : NSObject - (instancetype)initWithCellIdentifier:(NSString *)identifier parseQuery:(PFQuery *)query tableView:(UITableView *)tableView customizeBlock:(void (^)(ObjectType))customBlock; @end
这里是我试图在构造函数中初始化块的地方:
self.parseDatasource = [[ABParseDatasource alloc] initWithCellIdentifier:identifier parseQuery:[ABOrder query] tableView:self.tableView customizeBlock:^(ABOrderItemTableViewCell *cell) { }];
财产声明:
@property (nonatomic) ABParseDatasource *parseDatasource;
但是在实例化数据源时我遇到编译器错误:
有任何想法吗? (是的, ABOrderItemTableViewCell
inheritance自UITableViewCell
)
您必须在创建类时指定generics类型:
[[ABParseDatasource alloc] initWithCellIdentifier...