如何在Xcode 7中为块声明泛型类型

时间:2015-09-21 09:33:37

标签: ios objective-c generics block objective-c-blocks

我对Xcode 7中的泛型类型支持做了一个简单的测试,如下所示:

@interface MTBaseListViewController <T> : UIViewController

- (void )requestWithBlock1:(void (^)(T data ))block;
- (void )requestWithBlock2:(void (^)(MTListPagingModel<T> *data ))block;

@end;

接口编译没有问题。

然后在使用它的班级

@interface MTTestViewController : MTBaseListViewController <MTTestModel *>
@end

@implementation MTTestViewController

- (void )requestWithBlock1:(void (^)(MTTestModel *data ))block {
}

- (void )requestWithBlock2:(void (^)(MTListPagingModel<MTTestModel *> *data ))block {
}

@end

两种方法都会抱怨“实施中的参数类型冲突......”

我在enumerateObjectsUsingBlock支持类型中看到NSArray<ObjectType> (NSExtendedArray )方法在块内推断。所以我认为应该是我的问题没有以正确的方式声明类型?

0 个答案:

没有答案