- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在研究 RestKit 框架及其工作原理。然后我创建一个简单的项目,它将调用 Github api 并将数据加载到 TableView 中 - 在我阅读了一些教程之后 - 关于从远程加载和映射它工作正常并加载到 TableView 但是当我试图从中获取时数据存储 - 离线模式 - 应用程序将崩溃,这是日志:
2012-07-29 16:21:41.611 RKGithubClient_FromZtoH[29181:c07] I restkit:RKLog.m:33 RestKit initialized...
2012-07-29 16:21:53.161 RKGithubClient_FromZtoH[29181:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'executeFetchRequest:error: A fetch request must have an entity.'
*** First throw call stack:
(0x20b9022 0x197acd6 0xf15871 0x643c 0x42e5 0x3e14 0x4697 0x53838f 0x5385eb 0x5394ed 0x4a6a0c 0x4abf92 0x4a614b 0x495550 0x495670 0x495836 0x49c72a 0x2a6a 0x46d386 0x46e274 0x47d183 0x47dc38 0x471634 0x25e1ef5 0x208d195 0x1ff1ff2 0x1ff08da 0x1fefd84 0x1fefc9b 0x46dc65 0x46f626 0x259d 0x2505)
terminate called throwing an exception
这是 fetchFromDataStore 方法:
- (void)fetchFromDataStore
{
NSFetchRequest *request = [[[RKObjectManager sharedManager] mappingProvider] fetchRequestForResourcePath:self.resourcePath]; //self resourcePath]];
self.repos = [GithubRepo objectsWithFetchRequest:request];
[self.tableView reloadData];
}
知道为什么会发生这种情况,因为我已经为它们创建了实体,您可以从此链接查看源代码:
此外,是否有任何有用的 RestKit 缓存示例或教程?
谢谢,
最佳答案
最后,我得到了答案..
问题与以下事实有关,当我要求:NSFetchRequest *request = [[[RKObjectManager sharedManager] mappingProvider] fetchRequestForResourcePath:self.resourcePath];在 myViewController.m 上,它返回为空。发生这种情况的原因是对象映射器未配置为正确处理核心数据缓存。我正在使用:
- (void)setObjectMapping:(RKObjectMappingDefinition *)objectMapping forResourcePathPattern:(NSString *)resourcePathPattern;
当我应该使用:
- (void)setObjectMapping:(RKObjectMappingDefinition *)objectMapping forResourcePathPattern:(NSString *)resourcePathPattern withFetchRequestBlock:(RKObjectMappingProviderFetchRequestBlock)fetchRequestBlock;
它存在于对象映射的核心数据扩展中。您提供的额外 block 用于决定需要哪个提取请求,具体取决于 resourcePath 中传递的参数(在本例中为用户 RestKit)。在特定情况下,当 repo 用户 ==“RestKit”时,我想返回一个查找 repo 的提取请求。
虽然很难找到有关此方法的文档,但它非常有用:
/**
Configures an object mapping to be used when during a load event where the resourcePath of
the RKObjectLoader instance matches resourcePathPattern.
The resourcePathPattern is a SOCKit pattern matching property names preceded by colons within
a path. For example, if a collection of reviews for a product were loaded from a remote system
at the resourcePath @"/products/1234/reviews", object mapping could be configured to handle
this request with a resourcePathPattern of @"/products/:productID/reviews".
**NOTE** that care must be taken when configuring patterns within the provider. The patterns
will be evaluated in the order they are added to the provider, so more specific patterns must
precede more general patterns where either would generate a match.
@param objectMapping The object mapping to use when the resourcePath matches the specified
resourcePathPattern.
@param resourcePathPattern A pattern to be evaluated using an RKPathMatcher against a resourcePath
to determine if objectMapping is the appropriate mapping.
@param fetchRequestBlock A block that accepts an individual resourcePath and returns an NSFetchRequest
that should be used to fetch the local objects associated with resourcePath from CoreData, for use in
properly processing local deletes
@see RKPathMatcher
@see RKURL
@see RKObjectLoader
*/
- (void)setObjectMapping:(RKObjectMappingDefinition *)objectMapping forResourcePathPattern:(NSString *)resourcePathPattern withFetchRequestBlock:(RKObjectMappingProviderFetchRequestBlock)fetchRequestBlock;
关于objective-c - RestKit - fetchFromDataStore(缓存)问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11756210/
我使用 RestKit 与 REST api 进行交互。对于某些操作,例如 HTTP PUT/POST/DELETE,我只关心响应状态代码(200 或 500 等),而不关心响应数据,即使 API 确
我在客户端和服务器端都有一个这样的响应对象: 客户端: //BaseResponse.h @interface BaseResponse : NSObject{ NSString *code;
我正在尝试将 RestKit 0.20 集成到我的项目中,例如,我使用 google rss 阅读器作为示例项目。 这是对 Xml 的响应 / /类别> & 这是我必须从中获取数据的 Xml。 RKO
我很难使用 CocoaPods 将 RestKit 安装到我的项目中。我收到未找到的错误。 我的 Pods.xcconfig 看起来像这样: GCC_PREPROCESSOR_DEFINITIONS
大多数 RESTful API 都会路由对资源的访问,例如 Rabbit 对象,如下所示: GET /rabbits <--- GET all rabbits.
问题 在 iOS 上完成 Restkit 的安装说明后,我收到 Apple Mach-o 链接器错误: 我的流程 我尝试按照此处的 Restkit 安装说明进行操作:https://github.co
我完全按照此处找到的这些步骤操作: http://www.raywenderlich.com/13097/intro-to-restkit-tutorial 但是....我得到了错误: 这可能是什么原
我正在尝试使用 RestKit 调用需要基本身份验证的端点。 RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[JSNCateg
我想用RestKit ,但我已经使用 Realm.io而不是 CoreData。 是否可以在 Realm.io 之上使用 RestKit? 最佳答案 你当然可以。从 RestKit 取回对象后: //
我没有找到任何方法来设置 restkit 0.20.0 的超时间隔。 任何人都可以帮助增加超时间隔。 谢谢 最佳答案 子类 RKHTTPRequestOperation 和实现方法 - (NSURLR
我正在尝试实现 RESTKit 0.20 操作队列,我在博客上读到 NSOperationQueue 也可用于创建操作队列。我想使用 RestKit 操作队列的 native 方法。 任何人都可以发布
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 8年前关闭。 Improve thi
我在这里做的事情很奇怪吗? 我的类别得到下载和映射, 产品也像日志记录所说的那样被下载和映射, 但是我的产品在每个分类下都是空的,谢谢! { "productsCategories" : [
我尝试了几乎所有的解决方案,但都不适合我。我在 Xcode 6 上收到此错误。我也更新了 cocoa pod ,也更新了 pod 文件。 安装更新后,我在下面添加了几行: [!] From now o
我正在尝试使用 Jenkins-CI 自动构建一个使用 Restkit 的 iOS 项目,显然,restkit 作为一个项目驻留在主项目中。该项目使用 XCode-IDE 成功构建。 但是当我使用 x
我在 Xcode 6.1 中开发项目。它工作正常,突然提示错误“未找到 Restkit/Restkit.h 文件”。从 $ 更改Architectures 后出现错误(ARCHS_STANDARD_3
我按照 github 上的说明进行操作页面但有问题(肯定是我:P)但是,您知道在 Xcode4 RestKit 中集成/使用的任何好的教程吗? 谢谢! 最佳答案 从此链接下载最新版本 http://r
我在尝试让 RestKit 构建和工作时遇到了麻烦。我收到可怕的“词法或预处理器问题:未找到 RestKit/RestKit.h 文件”消息。我使用 Xcode 4.2,我的项目适用于 iOS。 早些
RKObjectManager *manager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:BASE_URL]]; PPPS
有没有办法使用对象管理器访问请求的成功块中的响应数据? [objectManager postObject:[User class] path:@"/users" parameters:nil suc
我是一名优秀的程序员,十分优秀!