Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
1b324cc
commit a545c39
Showing
32 changed files
with
647 additions
and
268 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// NSEntityDescription+RKAdditions.h | ||
// RestKit | ||
// | ||
// Created by Blake Watters on 3/22/12. | ||
// Copyright (c) 2012 RestKit. All rights reserved. | ||
// | ||
|
||
#import <CoreData/CoreData.h> | ||
|
||
/** | ||
The key for retrieving the name of the attribute that acts as | ||
the primary key from the user info dictionary of the receiving NSEntityDescription. | ||
**Value**: @"primaryKeyAttribute" | ||
*/ | ||
extern NSString * const RKEntityDescriptionPrimaryKeyAttributeUserInfoKey; | ||
|
||
/** | ||
Provides extensions to NSEntityDescription for various common tasks. | ||
*/ | ||
@interface NSEntityDescription (RKAdditions) | ||
|
||
/** | ||
The name of the attribute that acts as the primary key for the receiver. | ||
The primary key attribute can be configured in two ways: | ||
1. From within the Xcode Core Data editing view by | ||
adding the desired attribute's name as the value for the | ||
key `primaryKeyAttribute` to the user info dictionary. | ||
1. Programmatically, by retrieving the NSEntityDescription instance and | ||
setting the property's value. | ||
Programmatically configured values take precedence over the user info | ||
dictionary. | ||
*/ | ||
@property(nonatomic, retain) NSString *primaryKeyAttribute; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// RKFetchRequestManagedObjectCache.h | ||
// RestKit | ||
// | ||
// Created by Jeff Arena on 1/24/12. | ||
// Copyright (c) 2012 RestKit. All rights reserved. | ||
// | ||
|
||
#import "RKManagedObjectMappingCache.h" | ||
|
||
/** | ||
Provides a simple managed object cache strategy in which every request for an object | ||
is satisfied by dispatching an NSFetchRequest against the Core Data persistent store. | ||
Performance can be disappointing for data sets with a large amount of redundant data | ||
being mapped and connected together, but the memory footprint stays flat. | ||
*/ | ||
@interface RKFetchRequestManagedObjectCache : NSObject <RKManagedObjectCacheing> | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.