1

アプリケーションの 1 つで RestKit 0.10 から 0.20 に移行しています。https://github.com/RestKit/RestKit/wiki/Upgrading-from-v0.10.x-to-v0.20.0のページを確認しましたが、この問題は見られませんでした。

  • edit 2013-02-09 マッピング コードと loadObjectData メソッドを追加 *

RestKit は CocoaPods 経由で追加されました。

これは RK 0.10 で動作し、RK 0.20 でコンパイルされました。このフラグメントは次のことを行います。

  1. fetchRequest を作成する
  2. 述語を追加する
  3. 並べ替えを追加
  4. リピーターの配列を取得する

次のインポートがあります。

// RestKit
#import <RestKit/RestKit.h>
#import <RestKit/CoreData.h>

// Core Data
#import "Repeaters.h"

コードスニペット:

    NSArray *sortDescriptors;
*1  NSFetchRequest *sortedRequest = [Repeaters fetchRequest]; // RestKit 0.10
    // NSFetchRequest *sortedRequest = [NSFetchRequest fetchRequestWithEntityName:@"Repeaters"]; // RestKit 0.20?

    // Predicate Filter by Grouping
    NSString *predicateString = @"";

    if ([appDelegate getIncludeIrlpPreference]) {
        predicateString =  [predicateString stringByAppendingFormat:@"(grouping LIKE 'irlp')"];
    }

    if ([appDelegate getIncludeWsiPreference]) {
        if([predicateString length] > 0) predicateString = [predicateString stringByAppendingFormat:@" OR "];
        predicateString =  [predicateString stringByAppendingFormat:@"(grouping LIKE 'winsystem')"];
    }

    // Distance Sort
    if([selectedSegmentString isEqualToString:kRepeaterSortDistance]) {

        // Sort by distance
        NSSortDescriptor * sortBydistance = [[NSSortDescriptor alloc] initWithKey:@"distance" ascending:YES];
        sortDescriptors = [NSArray arrayWithObjects:sortBydistance, nil ];

    }

    // Add the Sort to the fetch request
    [sortedRequest setSortDescriptors:sortDescriptors];

    // Add the Predicate to the fetch request
    NSPredicate *predicate = [NSPredicate predicateWithFormat:predicateString];
    [sortedRequest setPredicate:predicate];

    // Fetch the data - filtered and sorted
*2  self.repeaters = [Repeaters objectsWithFetchRequest:sortedRequest]; // RestKit 0.10

Repeaters クラスのマッピング コード:

 RKManagedObjectMapping *repeatersMapping = [RKManagedObjectMapping mappingForEntityWithName:kEntityRepeaters inManagedObjectStore:objectStore];
 [repeatersMapping mapKeyPath:@"callSign" toAttribute:@"callSign"];
 [repeatersMapping mapKeyPath:@"country" toAttribute:@"country"];
 [repeatersMapping mapKeyPath:@"freqOffsetPl" toAttribute:@"freqOffsetPl"];
 [repeatersMapping mapKeyPath:@"grouping" toAttribute:@"grouping"];
 [repeatersMapping mapKeyPath:@"latitudeDefault" toAttribute:@"latitudeDefault"];
 [repeatersMapping mapKeyPath:@"longitudeDefault" toAttribute:@"longitudeDefault"];
 [repeatersMapping mapKeyPath:@"locationElevation" toAttribute:@"locationElevation"];
 [repeatersMapping mapKeyPath:@"node" toAttribute:@"node"];
 [repeatersMapping mapKeyPath:@"notes" toAttribute:@"notes"];
 [repeatersMapping mapKeyPath:@"repeaterId" toAttribute:@"repeaterId"];
 [repeatersMapping mapKeyPath:@"serviceArea" toAttribute:@"serviceArea"];
 [repeatersMapping mapKeyPath:@"serviceState" toAttribute:@"serviceState"];
 [repeatersMapping mapKeyPath:@"url" toAttribute:@"url"];
 repeatersMapping.primaryKeyAttribute = kEntityRepeaterKey;
 [wsiObjectManager.mappingProvider registerMapping:repeatersMapping withRootKeyPath:@"winSystem.winSystemRepeaters.winSystemRepeater"];

loadObjectData メソッド:

- (void)loadObjectData {

        [[RKObjectManager sharedManager] loadObjectsAtResourcePath:kWinSystemInfoXml delegate:self];
}

Xcode エラー:


*1 RepeatersTableViewController.m:116:37: セレクター「fetchRequest」の既知のクラス メソッドはありません

*2 RepeatersTableViewController.m:170:22: セレクター「objectsWithFetchRequest:」の既知のクラス メソッドはありません


コア データ ビットが Repeaters クラスに追加されていないようです。

v0.10 から v0.20 への変換に関する別のドキュメントはありますか?

4

1 に答える 1

1

あなたの質問を詳細に確認しなくても、https://github.com/RestKit/RestKit/wiki/Object-mappingは私のrestkit .20の質問の多くに答えています。

于 2013-02-06T01:51:16.710 に答える