0

我似乎能够很好地启动restkit并使用传统的loadobjectsatresourcepath:delegate:方法加载对象。但是,当我引入 block:^{} 时,restkit 每次都会崩溃。

[[RKObjectManager sharedManager] loadObjectsAtResourcePath:@"/api/v1/places" delegate:self block:^(RKObjectLoader* loader) {
    loader.objectMapping = [[RKObjectManager sharedManager].mappingProvider objectMappingForClass:[Place class]];
}];

我在日志中得到这个:

2012-05-12 19:07:32.266 App - [RKObjectManagerloadObjectsAtResourcePath:delegate:block:]: unrecognized selector sent to instance 0x3aa2e0
2012-05-12 19:07:32.268 App - *** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: '-[RKObjectManager   loadObjectsAtResourcePath:delegate:block:]: unrecognized selector sent to instance 0x3aa2e0'

关于如何解决这个问题的任何想法?谢谢!

4

1 回答 1

1

异常告诉您确切的问题是什么:RKObjectManager不响应loadObjectsAtResourcePath:delegate:block:. 快速浏览 API 文档会发现原始方法在 0.10.0 中不再存在,并且似乎已被替换为loadObjectsAtResourcePath:usingBlock:

您应该能够通过使用新方法来避免异常:

[[RKObjectManager sharedManager] loadObjectsAtResourcePath:@"/api/v1/places" usingBlock:^(RKObjectLoader* loader) {
    loader.objectMapping = [[RKObjectManager sharedManager].mappingProvider objectMappingForClass:[Place class]];
}];
于 2012-05-13T03:02:01.283 回答