8
A
回答
3
当然可以。一旦你从RestKit
// GET a single Article from /articles/1234.json and map it into an object
// JSON looks like {"article": {"title": "My Article", "author": "Blake", "body": "Very cool!!"}}
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[Article class]];
[mapping addAttributeMappingsFromArray:@[@"title", @"author", @"body"]];
NSIndexSet *statusCodes = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful); // Anything in 2xx
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:mapping method:RKRequestMethodAny pathPattern:@"/articles/:articleID" keyPath:@"article" statusCodes:statusCodes];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://restkit.org/articles/1234.json"]];
RKObjectRequestOperation *operation = [[RKObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[responseDescriptor]];
[operation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *result) {
Article *article = [result firstObject];
//I would put the Realm write here
NSLog(@"Mapped the article: %@", article);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"Failed with error: %@", [error localizedDescription]);
}];
[operation start];
获取对象后面你需要做两件事情:
- 创建从RLMObject 继承
那么你RealmArticle模型(在这种情况下),你只需要写入您的领域
RLMRealm *realm = [RLMRealm defaultRealm]; [realm beginWriteTransaction]; [RealmArticle createInDefaultRealmWithObject:article]; [realm commitWriteTransaction];
相关问题
- 1. Realm.IO - 可以使用createOrUpdateAllFromJson解析JSON数组吗?
- 2. 用Swift搜索Realm.io
- 3. 我如何可以打印Restkit(IOS)发送的身体
- 4. 我可以使用SimpleJaxWsServiceExporter和javax.servlet.Filter吗?
- 5. 我们可以使用AJAX和XHTML吗?
- 6. 我可以使用NativeActivity和ActivityGroup吗?
- 7. 我可以使用Switch Widget和ActionBarSherlock吗?
- 8. 我们可以使用CASE和EXEC
- 9. 我可以使用tempnam和IOS吗?
- 10. 使用ASIHTTPRequest的RestKit
- 11. 在库中使用realm.io时的NoSuchMethodError
- 12. 使用Realm.io与Swift的关系
- 13. 使用Realm.io存储货币值
- 14. Restkit和死锁
- 15. restkit和three20
- 16. 使用Restkit发送整数为json使用Restkit
- 17. 引用Realm.io FK对象ID
- 18. 我在哪里可以学习Oberon和我可以使用什么IDE
- 19. 备份和恢复realm.io数据库
- 20. 我可以使用XML
- 21. 我可以使用Delphi中
- 22. 我可以使用:目标
- 23. 我可以使用C#
- 24. 我可以使用Java中
- 25. 我可以使用代码
- 26. 我可以使用在Android
- 27. 哪jquery我可以使用?
- 28. 我可以使用yepnope/modernizer.load()
- 29. 我们可以使用JavaScript
- 30. 我可以使用PayPal吗?