コア データを NSTableView にバインドしようとしています。API から情報を取得し、それを NSTableView に追加したいと考えています。APIを呼び出して情報を取得するたびに、NSTableViewデータに空白行が追加されるため、正しくセットアップされているようです。
バインドしたデータの代わりに空白行を追加するのはなぜですか?
AppController.h
@property (nonatomic, strong) NSManagedObjectContext *managedObjectContext;
次に、自動シンセの新しい Xcode を使用しています。
Items.h
@class TimeLog;
@interface Items : NSManagedObject
@property (nonatomic, retain) NSNumber * itemId;
@property (nonatomic, retain) NSString * title;
@property (nonatomic, retain) NSString * itemType;
@property (nonatomic, retain) TimeLog *relationship;
@end
Items.m
@implementation Items
@dynamic itemId;
@dynamic title;
@dynamic itemType;
@dynamic relationship;
@end
ItemObject.h
@interface ItemObject : NSObject
@property (nonatomic, retain) NSString * itemId;
@property (nonatomic, retain) NSString * title;
@property (nonatomic, retain) NSString * itemType;
@end
ItemObject.m
@implementation ItemObject
@end
API 呼び出しを行うメソッド
このメソッドは API 呼び出しを行い、それを一時オブジェクトに追加します。次に、その一時オブジェクトをコア データに追加します。
+ (void)searchForItemByType:(NSString *)itemType andId:(NSString *)searchId
{
NSLog(@"Search Feature By ID: %@", searchId);
RKObjectMapping *itemMapping = [RKObjectMapping mappingForClass:[ItemObject class]];
[itemMapping addAttributeMappingsFromDictionary:@{
@"id": @"itemId",
@"name": @"title",
@"item_type": @"itemType"
}];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:itemMapping pathPattern:nil keyPath:@"data" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
RKObjectMapping *errorMapping = [RKObjectMapping mappingForClass:[RKErrorMessage class]];
// The entire value at the source key path containing the errors maps to the message
[errorMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:nil toKeyPath:@"errorMessage"]];
NSIndexSet *statusCodes = RKStatusCodeIndexSetForClass(RKStatusCodeClassClientError);
// Any response in the 4xx status code range with an "errors" key path uses this mapping
RKResponseDescriptor *errorDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:errorMapping pathPattern:nil keyPath:@"error_description" statusCodes:statusCodes];
RKObjectManager *manager = [RKObjectManager sharedManager];
NSLog(@"HTTP Client: %@", manager.HTTPClient);
[manager addResponseDescriptorsFromArray:@[ responseDescriptor, errorDescriptor ]];
// NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
@"false", @"with_lock"
, nil];
NSString *path = [NSString stringWithFormat:@"/api/v1/%@/%@", [itemType lowercaseString], searchId];
NSLog(@"Manager: %@", manager);
[manager getObjectsAtPath:path parameters:params success:^(RKObjectRequestOperation *operation, RKMappingResult *result) {
NSLog(@"Results: %@", [result firstObject]);
Items *insertItem = [NSEntityDescription insertNewObjectForEntityForName:@"Items" inManagedObjectContext:[[CoreDataHelper sharedInstance] managedObjectContext]];
insertItem = [result firstObject];
NSLog(@"Name: %@", [insertItem title]);
// Handled with articleDescriptor
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
// Transport error or server error handled by errorDescriptor
NSLog(@"Error: %@", [error localizedDescription]);
NSAlert *alert = [NSAlert alertWithMessageText:@"Error" defaultButton:@"OK" alternateButton:nil otherButton:nil informativeTextWithFormat:@"%@", [error localizedDescription]];
[alert runModal];
}];
}
上記のコードからのログ
2013-03-15 10:15:21.817 Project[59074:403] Results: <ItemObject: 0x1034ab360>
2013-03-15 10:15:21.818 Project[59074:403] ManagedObjectContext
2013-03-15 10:15:21.818 Project[59074:403] Name: Custom Mod is missing from Face Lift
IB