我在我的一个应用程序中从RestKit 0.10移动到0.20。我在https://github.com/RestKit/RestKit/wiki/Upgrading-from-v0.10.x-to-v0.20.0处查看了该页面,但没有看到此问题。
RestKit是通过CocoaPods添加的。
这是在RK 0.10中工作,然后在RK 0.20中编译。这个片段确实:
我按顺序进行了以下导入:
// 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:'
没有已知的类方法就像核心数据位没有被添加到Repeater类中一样。
是否有另一个v0.10到v0.20转换的文档可以帮助我查看更多更改?
答案 0 :(得分:1)
在没有详细审核您的问题的情况下,https://github.com/RestKit/RestKit/wiki/Object-mapping回答了我的许多问题.20。问题。