Files
RestKit/Code/CoreData/NSEntityDescription+RKAdditions.m
Blake Watters a545c3942b Integrated primaryKey extension to NSEntityDescription and refactored cache strategy
classes to eliminate issues with duplicated objects. closes #611, #612, #613, #618

* NSEntityDescription is now aware of the primaryKeyAttribute. Can be configured via
Interface Builder within Xcode or programatically.
* Added findByPrimaryKey: interface to the Core Data extensions.
* Relaxed dependencies on RKManagedObjectMapping across the system now that primaryKey is
available without a reference to the mapping.
2012-04-03 23:39:42 -04:00

39 lines
1.1 KiB
Objective-C

//
// NSEntityDescription+RKAdditions.m
// RestKit
//
// Created by Blake Watters on 3/22/12.
// Copyright (c) 2012 RestKit. All rights reserved.
//
#import <objc/runtime.h>
#import "NSEntityDescription+RKAdditions.h"
NSString * const RKEntityDescriptionPrimaryKeyAttributeUserInfoKey = @"primaryKeyAttribute";
static char primaryKeyAttributeKey;
@implementation NSEntityDescription (RKAdditions)
- (NSString *)primaryKeyAttribute
{
// Check for an associative object reference
NSString *primaryKeyAttribute = (NSString *) objc_getAssociatedObject(self, &primaryKeyAttributeKey);
// Fall back to the userInfo dictionary
if (! primaryKeyAttribute) {
primaryKeyAttribute = [self.userInfo valueForKey:RKEntityDescriptionPrimaryKeyAttributeUserInfoKey];
}
return primaryKeyAttribute;
}
- (void)setPrimaryKeyAttribute:(NSString *)primaryKeyAttribute
{
objc_setAssociatedObject(self,
&primaryKeyAttributeKey,
primaryKeyAttribute,
OBJC_ASSOCIATION_RETAIN);
}
@end