3

私はRestKitフレームワークとそれがどのように機能するかを見ていました。次に、Github apiを呼び出してデータをテーブルビューにロードする簡単なプロジェクトを作成します-いくつかのチュートリアルを読んだ後-、リモートからのロードとマッピングに関しては、正常に動作し、テーブルビューにロードされますが、フェッチしようとするとデータストア -オフライン モード - アプリがクラッシュし、これがログです:

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 キャッシュに関する有用な例やチュートリアルはありますか?

ありがとう、

4

1 に答える 1

2

最後に、私はそれに対する答えを得ました..

この問題は、次のように要求すると、次のようになるという事実に関連しています。myViewController.m では、空に戻ります。これが発生する理由は、オブジェクト マッパーがコア データ キャッシュを正しく処理するように構成されていないためです。私は使用しています:

- (void)setObjectMapping:(RKObjectMappingDefinition *)objectMapping forResourcePathPattern:(NSString *)resourcePathPattern;

私が使用する必要がある間:

- (void)setObjectMapping:(RKObjectMappingDefinition *)objectMapping forResourcePathPattern:(NSString *)resourcePathPattern withFetchRequestBlock:(RKObjectMappingProviderFetchRequestBlock)fetchRequestBlock;

これは、オブジェクト マッピングのコア データ拡張に存在します。指定した追加のブロックは、resourcePath (この場合はユーザー RestKit) で渡されたパラメーターに応じて、どのフェッチ要求が必要かを決定する目的に役立ちます。特定のケースでは、レポのユーザー == "RestKit" のときにレポを探すフェッチ リクエストを返したいと思います。

ドキュメントは、このメソッドを見つけるのは難しいですが、かなり役に立ちます:

/**
 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;
于 2012-09-01T06:36:13.227 に答える