我正在我的一个应用程序上从 RestKit 0.10 迁移到 0.20。我查看了https://github.com/RestKit/RestKit/wiki/Upgrading-from-v0.10.x-to-v0.20.0上的页面,但没有看到这个问题。
- 编辑 2013-02-09 添加映射代码和 loadObjectData 方法 *
RestKit 是通过 CocoaPods 添加的。
这在 RK 0.10 中工作,然后在 RK 0.20 中编译。这个片段做:
- 创建 fetchRequest
- 添加谓词
- 添加排序
- 获取中继器数组
我有以下进口,按顺序:
// 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"];
加载对象数据方法:
- (void)loadObjectData {
[[RKObjectManager sharedManager] loadObjectsAtResourcePath:kWinSystemInfoXml delegate:self];
}
Xcode 错误:
*1 RepeatersTableViewController.m:116:37:选择器“fetchRequest”没有已知的类方法
*2 RepeatersTableViewController.m:170:22: 选择器“objectsWithFetchRequest:”没有已知的类方法
就像没有将核心数据位添加到中继器类中一样。
是否有另一份 v0.10 到 v0.20 转换的文档可以帮助我查看更多更改?