全て、
どこにも答えが見つからないので、これは私だけが欠けている答えに違いありません。
私はiosでRestKitを学んでおり、最終的に関係を完成させてJSONを適切に消費することができました(woohoo!)。
ただし、親クラスから子クラスのフィールド/データにアクセスする方法がわかりません。
JSON の例: { events { name : "Fitness Walk", desc : "walking in circles" location { placename : "your backyard", longitude : -40.1234, latitude : 38.5678, address : "1600 Penn" } }
イベントクラスとロケーションクラスがあります。イベント クラスには、メンバー変数 (EventLocation * toLocation) として場所へのポインターがあり、関係が含まれます。
[RKObjectManager setSharedManager:objectManager];
RKEntityMapping * locationMapping = [RKEntityMapping mappingForEntityForName:@"EventLocation" inManagedObjectStore:managedObjectStore];
NSDictionary * locationInfo = @{ @"placename" : @"eventPlaceName", @"longitude" : @"longitude", @"latitude" : @"latitude", @"address" : @"eventAddress" };
[locationMapping addAttributeMappingsFromDictionary:locationInfo];
RKEntityMapping * eventMapping = [RKEntityMapping mappingForEntityForName:@"NYCEvent" inManagedObjectStore:managedObjectStore];
NSDictionary * eventInfo = @{ @"_id" : @"event_id", @"name" : @"event_name",@"desc" : @"event_description" };
[eventMapping addAttributeMappingsFromDictionary:eventInfo];
[eventMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"location" toKeyPath:@"toLocation" withMapping:locationMapping]];
RKResponseDescriptor * responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:eventMapping pathPattern:@"/api/search" keyPath:@"events" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
チュートリアルのように、eventPlaceName テキストをサブタイトルとして UITableViewCell に入れたいと思います。
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
NSManagedObject *object = [self.fetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = [[object valueForKey:@"event_name"] description];
NSString * lbl = < somehow get the event place name>;
cell.detailTextLabel.text = lbl;
}
しかし、方法がわかりません。お願い助けて?
ありがとう!:bp: