mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-23 12:27:52 +08:00
Ensure the stars for all pointers belong to the variable rather than the type. Refs #614
This commit is contained in:
@@ -31,59 +31,59 @@
|
||||
* The NSEntityDescription for the Subclass
|
||||
* defaults to the subclass className, may be overridden
|
||||
*/
|
||||
+ (NSEntityDescription*)entity;
|
||||
+ (NSEntityDescription *)entity;
|
||||
|
||||
/**
|
||||
* Returns an initialized NSFetchRequest for the entity, with no predicate
|
||||
*/
|
||||
+ (NSFetchRequest*)fetchRequest;
|
||||
+ (NSFetchRequest *)fetchRequest;
|
||||
|
||||
/**
|
||||
* Fetches all objects from the persistent store identified by the fetchRequest
|
||||
*/
|
||||
+ (NSArray*)objectsWithFetchRequest:(NSFetchRequest*)fetchRequest;
|
||||
+ (NSArray *)objectsWithFetchRequest:(NSFetchRequest *)fetchRequest;
|
||||
|
||||
/**
|
||||
* Retrieves the number of objects that would be retrieved by the fetchRequest,
|
||||
* if executed
|
||||
*/
|
||||
+ (NSUInteger)countOfObjectsWithFetchRequest:(NSFetchRequest*)fetchRequest;
|
||||
+ (NSUInteger)countOfObjectsWithFetchRequest:(NSFetchRequest *)fetchRequest;
|
||||
|
||||
/**
|
||||
* Fetches all objects from the persistent store via a set of fetch requests and
|
||||
* returns all results in a single array.
|
||||
*/
|
||||
+ (NSArray*)objectsWithFetchRequests:(NSArray*)fetchRequests;
|
||||
+ (NSArray *)objectsWithFetchRequests:(NSArray *)fetchRequests;
|
||||
|
||||
/**
|
||||
* Fetches the first object identified by the fetch request. A limit of one will be
|
||||
* applied to the fetch request before dispatching.
|
||||
*/
|
||||
+ (id)objectWithFetchRequest:(NSFetchRequest*)fetchRequest;
|
||||
+ (id)objectWithFetchRequest:(NSFetchRequest *)fetchRequest;
|
||||
|
||||
/**
|
||||
* Fetches all objects from the persistent store by constructing a fetch request and
|
||||
* applying the predicate supplied. A short-cut for doing filtered searches on the objects
|
||||
* of this class under management.
|
||||
*/
|
||||
+ (NSArray*)objectsWithPredicate:(NSPredicate*)predicate;
|
||||
+ (NSArray *)objectsWithPredicate:(NSPredicate *)predicate;
|
||||
|
||||
/**
|
||||
* Fetches the first object matching a predicate from the persistent store. A fetch request
|
||||
* will be constructed for you and a fetch limit of 1 will be applied.
|
||||
*/
|
||||
+ (id)objectWithPredicate:(NSPredicate*)predicate;
|
||||
+ (id)objectWithPredicate:(NSPredicate *)predicate;
|
||||
|
||||
/**
|
||||
* Fetches all managed objects of this class from the persistent store as an array
|
||||
*/
|
||||
+ (NSArray*)allObjects;
|
||||
+ (NSArray *)allObjects;
|
||||
|
||||
/**
|
||||
* Returns a count of all managed objects of this class in the persistent store. On
|
||||
* error, will populate the error argument
|
||||
*/
|
||||
+ (NSUInteger)count:(NSError**)error;
|
||||
+ (NSUInteger)count:(NSError **)error;
|
||||
|
||||
/**
|
||||
* Returns a count of all managed objects of this class in the persistent store. Deprecated
|
||||
@@ -124,7 +124,7 @@
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
+ (NSManagedObjectContext*)currentContext;
|
||||
+ (NSManagedObjectContext *)currentContext;
|
||||
|
||||
+ (void)handleErrors:(NSError *)error;
|
||||
|
||||
|
||||
@@ -54,13 +54,13 @@ RK_FIX_CATEGORY_BUG(NSManagedObject_ActiveRecord)
|
||||
|
||||
#pragma mark - RKManagedObject methods
|
||||
|
||||
+ (NSEntityDescription*)entity
|
||||
+ (NSEntityDescription *)entity
|
||||
{
|
||||
NSString* className = [NSString stringWithCString:class_getName([self class]) encoding:NSASCIIStringEncoding];
|
||||
NSString *className = [NSString stringWithCString:class_getName([self class]) encoding:NSASCIIStringEncoding];
|
||||
return [NSEntityDescription entityForName:className inManagedObjectContext:[NSManagedObjectContext contextForCurrentThread]];
|
||||
}
|
||||
|
||||
+ (NSFetchRequest*)fetchRequest
|
||||
+ (NSFetchRequest *)fetchRequest
|
||||
{
|
||||
NSFetchRequest *fetchRequest = [[[NSFetchRequest alloc] init] autorelease];
|
||||
NSEntityDescription *entity = [self entity];
|
||||
@@ -68,19 +68,19 @@ RK_FIX_CATEGORY_BUG(NSManagedObject_ActiveRecord)
|
||||
return fetchRequest;
|
||||
}
|
||||
|
||||
+ (NSArray*)objectsWithFetchRequest:(NSFetchRequest*)fetchRequest
|
||||
+ (NSArray *)objectsWithFetchRequest:(NSFetchRequest *)fetchRequest
|
||||
{
|
||||
NSError* error = nil;
|
||||
NSArray* objects = [[NSManagedObjectContext contextForCurrentThread] executeFetchRequest:fetchRequest error:&error];
|
||||
NSError *error = nil;
|
||||
NSArray *objects = [[NSManagedObjectContext contextForCurrentThread] executeFetchRequest:fetchRequest error:&error];
|
||||
if (objects == nil) {
|
||||
RKLogError(@"Error: %@", [error localizedDescription]);
|
||||
}
|
||||
return objects;
|
||||
}
|
||||
|
||||
+ (NSUInteger)countOfObjectsWithFetchRequest:(NSFetchRequest*)fetchRequest
|
||||
+ (NSUInteger)countOfObjectsWithFetchRequest:(NSFetchRequest *)fetchRequest
|
||||
{
|
||||
NSError* error = nil;
|
||||
NSError *error = nil;
|
||||
NSUInteger objectCount = [[NSManagedObjectContext contextForCurrentThread] countForFetchRequest:fetchRequest error:&error];
|
||||
if (objectCount == NSNotFound) {
|
||||
RKLogError(@"Error: %@", [error localizedDescription]);
|
||||
@@ -88,21 +88,21 @@ RK_FIX_CATEGORY_BUG(NSManagedObject_ActiveRecord)
|
||||
return objectCount;
|
||||
}
|
||||
|
||||
+ (NSArray*)objectsWithFetchRequests:(NSArray*)fetchRequests
|
||||
+ (NSArray *)objectsWithFetchRequests:(NSArray *)fetchRequests
|
||||
{
|
||||
NSMutableArray* mutableObjectArray = [[NSMutableArray alloc] init];
|
||||
for (NSFetchRequest* fetchRequest in fetchRequests) {
|
||||
NSMutableArray *mutableObjectArray = [[NSMutableArray alloc] init];
|
||||
for (NSFetchRequest *fetchRequest in fetchRequests) {
|
||||
[mutableObjectArray addObjectsFromArray:[self objectsWithFetchRequest:fetchRequest]];
|
||||
}
|
||||
NSArray* objects = [NSArray arrayWithArray:mutableObjectArray];
|
||||
NSArray *objects = [NSArray arrayWithArray:mutableObjectArray];
|
||||
[mutableObjectArray release];
|
||||
return objects;
|
||||
}
|
||||
|
||||
+ (id)objectWithFetchRequest:(NSFetchRequest*)fetchRequest
|
||||
+ (id)objectWithFetchRequest:(NSFetchRequest *)fetchRequest
|
||||
{
|
||||
[fetchRequest setFetchLimit:1];
|
||||
NSArray* objects = [self objectsWithFetchRequest:fetchRequest];
|
||||
NSArray *objects = [self objectsWithFetchRequest:fetchRequest];
|
||||
if ([objects count] == 0) {
|
||||
return nil;
|
||||
} else {
|
||||
@@ -110,28 +110,28 @@ RK_FIX_CATEGORY_BUG(NSManagedObject_ActiveRecord)
|
||||
}
|
||||
}
|
||||
|
||||
+ (NSArray*)objectsWithPredicate:(NSPredicate*)predicate
|
||||
+ (NSArray *)objectsWithPredicate:(NSPredicate *)predicate
|
||||
{
|
||||
NSFetchRequest* fetchRequest = [self fetchRequest];
|
||||
NSFetchRequest *fetchRequest = [self fetchRequest];
|
||||
[fetchRequest setPredicate:predicate];
|
||||
return [self objectsWithFetchRequest:fetchRequest];
|
||||
}
|
||||
|
||||
+ (id)objectWithPredicate:(NSPredicate*)predicate
|
||||
+ (id)objectWithPredicate:(NSPredicate *)predicate
|
||||
{
|
||||
NSFetchRequest* fetchRequest = [self fetchRequest];
|
||||
NSFetchRequest *fetchRequest = [self fetchRequest];
|
||||
[fetchRequest setPredicate:predicate];
|
||||
return [self objectWithFetchRequest:fetchRequest];
|
||||
}
|
||||
|
||||
+ (NSArray*)allObjects
|
||||
+ (NSArray *)allObjects
|
||||
{
|
||||
return [self objectsWithPredicate:nil];
|
||||
}
|
||||
|
||||
+ (NSUInteger)count:(NSError**)error
|
||||
+ (NSUInteger)count:(NSError **)error
|
||||
{
|
||||
NSFetchRequest* fetchRequest = [self fetchRequest];
|
||||
NSFetchRequest *fetchRequest = [self fetchRequest];
|
||||
return [[NSManagedObjectContext contextForCurrentThread] countForFetchRequest:fetchRequest error:error];
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ RK_FIX_CATEGORY_BUG(NSManagedObject_ActiveRecord)
|
||||
|
||||
#pragma mark - MagicalRecord Ported Methods
|
||||
|
||||
+ (NSManagedObjectContext*)currentContext;
|
||||
+ (NSManagedObjectContext *)currentContext;
|
||||
{
|
||||
return [NSManagedObjectContext contextForCurrentThread];
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@
|
||||
*/
|
||||
@interface RKManagedObjectLoader : RKObjectLoader {
|
||||
RKManagedObjectStore *_objectStore;
|
||||
NSManagedObjectID* _targetObjectID;
|
||||
NSMutableSet* _managedObjectKeyPaths;
|
||||
NSManagedObjectID *_targetObjectID;
|
||||
NSMutableSet *_managedObjectKeyPaths;
|
||||
BOOL _deleteObjectOnFailure;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
|
||||
@see RKManagedObjectStore
|
||||
*/
|
||||
@property (nonatomic, retain) RKManagedObjectStore* objectStore;
|
||||
@property (nonatomic, retain) RKManagedObjectStore *objectStore;
|
||||
|
||||
+ (id)loaderWithURL:(RKURL *)URL mappingProvider:(RKObjectMappingProvider *)mappingProvider objectStore:(RKManagedObjectStore *)objectStore;
|
||||
- (id)initWithURL:(RKURL *)URL mappingProvider:(RKObjectMappingProvider *)mappingProvider objectStore:(RKManagedObjectStore *)objectStore;
|
||||
|
||||
@@ -82,7 +82,7 @@
|
||||
|
||||
#pragma mark - RKObjectMapperDelegate methods
|
||||
|
||||
- (void)objectMapper:(RKObjectMapper*)objectMapper didMapFromObject:(id)sourceObject toObject:(id)destinationObject atKeyPath:(NSString*)keyPath usingMapping:(RKObjectMapping*)objectMapping
|
||||
- (void)objectMapper:(RKObjectMapper *)objectMapper didMapFromObject:(id)sourceObject toObject:(id)destinationObject atKeyPath:(NSString *)keyPath usingMapping:(RKObjectMapping *)objectMapping
|
||||
{
|
||||
if ([destinationObject isKindOfClass:[NSManagedObject class]]) {
|
||||
[_managedObjectKeyPaths addObject:keyPath];
|
||||
@@ -101,7 +101,7 @@
|
||||
return _targetObject;
|
||||
}
|
||||
|
||||
- (void)setTargetObject:(NSObject*)targetObject
|
||||
- (void)setTargetObject:(NSObject *)targetObject
|
||||
{
|
||||
[_targetObject release];
|
||||
_targetObject = nil;
|
||||
@@ -119,9 +119,9 @@
|
||||
// right before send to avoid sequencing issues where the target object is
|
||||
// set before the managed object store.
|
||||
if (self.targetObject && [self.targetObject isKindOfClass:[NSManagedObject class]]) {
|
||||
_deleteObjectOnFailure = [(NSManagedObject*)self.targetObject isNew];
|
||||
_deleteObjectOnFailure = [(NSManagedObject *)self.targetObject isNew];
|
||||
[self.objectStore save:nil];
|
||||
_targetObjectID = [[(NSManagedObject*)self.targetObject objectID] retain];
|
||||
_targetObjectID = [[(NSManagedObject *)self.targetObject objectID] retain];
|
||||
}
|
||||
|
||||
return [super prepareURLRequest];
|
||||
@@ -137,7 +137,7 @@
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)deleteCachedObjectsMissingFromResult:(RKObjectMappingResult*)result
|
||||
- (void)deleteCachedObjectsMissingFromResult:(RKObjectMappingResult *)result
|
||||
{
|
||||
if (! [self isGET]) {
|
||||
RKLogDebug(@"Skipping cleanup of objects via managed object cache: only used for GET requests.");
|
||||
@@ -159,11 +159,11 @@
|
||||
}
|
||||
|
||||
// NOTE: We are on the background thread here, be mindful of Core Data's threading needs
|
||||
- (void)processMappingResult:(RKObjectMappingResult*)result
|
||||
- (void)processMappingResult:(RKObjectMappingResult *)result
|
||||
{
|
||||
NSAssert(_sentSynchronously || ![NSThread isMainThread], @"Mapping result processing should occur on a background thread");
|
||||
if (_targetObjectID && self.targetObject && self.method == RKRequestMethodDELETE) {
|
||||
NSManagedObject* backgroundThreadObject = [self.objectStore objectWithID:_targetObjectID];
|
||||
NSManagedObject *backgroundThreadObject = [self.objectStore objectWithID:_targetObjectID];
|
||||
RKLogInfo(@"Deleting local object %@ due to DELETE request", backgroundThreadObject);
|
||||
[[self.objectStore managedObjectContextForCurrentThread] deleteObject:backgroundThreadObject];
|
||||
}
|
||||
@@ -175,8 +175,8 @@
|
||||
BOOL success = [self.objectStore save:&error];
|
||||
if (! success) {
|
||||
RKLogError(@"Failed to save managed object context after mapping completed: %@", [error localizedDescription]);
|
||||
NSMethodSignature* signature = [(NSObject *)self methodSignatureForSelector:@selector(informDelegateOfError:)];
|
||||
RKManagedObjectThreadSafeInvocation* invocation = [RKManagedObjectThreadSafeInvocation invocationWithMethodSignature:signature];
|
||||
NSMethodSignature *signature = [(NSObject *)self methodSignatureForSelector:@selector(informDelegateOfError:)];
|
||||
RKManagedObjectThreadSafeInvocation *invocation = [RKManagedObjectThreadSafeInvocation invocationWithMethodSignature:signature];
|
||||
[invocation setTarget:self];
|
||||
[invocation setSelector:@selector(informDelegateOfError:)];
|
||||
[invocation setArgument:&error atIndex:2];
|
||||
@@ -189,9 +189,9 @@
|
||||
}
|
||||
}
|
||||
|
||||
NSDictionary* dictionary = [result asDictionary];
|
||||
NSMethodSignature* signature = [self methodSignatureForSelector:@selector(informDelegateOfObjectLoadWithResultDictionary:)];
|
||||
RKManagedObjectThreadSafeInvocation* invocation = [RKManagedObjectThreadSafeInvocation invocationWithMethodSignature:signature];
|
||||
NSDictionary *dictionary = [result asDictionary];
|
||||
NSMethodSignature *signature = [self methodSignatureForSelector:@selector(informDelegateOfObjectLoadWithResultDictionary:)];
|
||||
RKManagedObjectThreadSafeInvocation *invocation = [RKManagedObjectThreadSafeInvocation invocationWithMethodSignature:signature];
|
||||
[invocation setObjectStore:self.objectStore];
|
||||
[invocation setTarget:self];
|
||||
[invocation setSelector:@selector(informDelegateOfObjectLoadWithResultDictionary:)];
|
||||
@@ -208,7 +208,7 @@
|
||||
if (_targetObjectID) {
|
||||
if (_deleteObjectOnFailure) {
|
||||
RKLogInfo(@"Error response encountered: Deleting existing managed object with ID: %@", _targetObjectID);
|
||||
NSManagedObject* objectToDelete = [self.objectStore objectWithID:_targetObjectID];
|
||||
NSManagedObject *objectToDelete = [self.objectStore objectWithID:_targetObjectID];
|
||||
if (objectToDelete) {
|
||||
[[self.objectStore managedObjectContextForCurrentThread] deleteObject:objectToDelete];
|
||||
[self.objectStore save:nil];
|
||||
@@ -224,7 +224,7 @@
|
||||
- (BOOL)isResponseMappable
|
||||
{
|
||||
if ([self.response wasLoadedFromCache]) {
|
||||
NSArray* cachedObjects = [self cachedObjects];
|
||||
NSArray *cachedObjects = [self cachedObjects];
|
||||
if (! cachedObjects) {
|
||||
RKLogDebug(@"Skipping managed object mapping optimization -> Managed object cache returned nil cachedObjects for resourcePath: %@", self.resourcePath);
|
||||
return [super isResponseMappable];
|
||||
|
||||
@@ -48,18 +48,18 @@
|
||||
return [self mappingForEntityWithName:NSStringFromClass(objectClass) inManagedObjectStore:objectStore];
|
||||
}
|
||||
|
||||
+ (RKManagedObjectMapping *)mappingForEntity:(NSEntityDescription*)entity inManagedObjectStore:(RKManagedObjectStore *)objectStore
|
||||
+ (RKManagedObjectMapping *)mappingForEntity:(NSEntityDescription *)entity inManagedObjectStore:(RKManagedObjectStore *)objectStore
|
||||
{
|
||||
return [[[self alloc] initWithEntity:entity inManagedObjectStore:objectStore] autorelease];
|
||||
}
|
||||
|
||||
+ (RKManagedObjectMapping *)mappingForEntityWithName:(NSString*)entityName inManagedObjectStore:(RKManagedObjectStore *)objectStore
|
||||
+ (RKManagedObjectMapping *)mappingForEntityWithName:(NSString *)entityName inManagedObjectStore:(RKManagedObjectStore *)objectStore
|
||||
{
|
||||
return [self mappingForEntity:[NSEntityDescription entityForName:entityName inManagedObjectContext:objectStore.primaryManagedObjectContext]
|
||||
inManagedObjectStore:objectStore];
|
||||
}
|
||||
|
||||
- (id)initWithEntity:(NSEntityDescription*)entity inManagedObjectStore:(RKManagedObjectStore*)objectStore
|
||||
- (id)initWithEntity:(NSEntityDescription *)entity inManagedObjectStore:(RKManagedObjectStore *)objectStore
|
||||
{
|
||||
NSAssert(entity, @"Cannot initialize an RKManagedObjectMapping without an entity. Maybe you want RKObjectMapping instead?");
|
||||
NSAssert(objectStore, @"Object store cannot be nil");
|
||||
@@ -98,23 +98,23 @@
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSDictionary*)relationshipsAndPrimaryKeyAttributes
|
||||
- (NSDictionary *)relationshipsAndPrimaryKeyAttributes
|
||||
{
|
||||
return _relationshipToPrimaryKeyMappings;
|
||||
}
|
||||
|
||||
- (void)connectRelationship:(NSString*)relationshipName withObjectForPrimaryKeyAttribute:(NSString*)primaryKeyAttribute
|
||||
- (void)connectRelationship:(NSString *)relationshipName withObjectForPrimaryKeyAttribute:(NSString *)primaryKeyAttribute
|
||||
{
|
||||
NSAssert([_relationshipToPrimaryKeyMappings objectForKey:relationshipName] == nil, @"Cannot add connect relationship %@ by primary key, a mapping already exists.", relationshipName);
|
||||
[_relationshipToPrimaryKeyMappings setObject:primaryKeyAttribute forKey:relationshipName];
|
||||
}
|
||||
|
||||
- (void)connectRelationshipsWithObjectsForPrimaryKeyAttributes:(NSString*)firstRelationshipName, ...
|
||||
- (void)connectRelationshipsWithObjectsForPrimaryKeyAttributes:(NSString *)firstRelationshipName, ...
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, firstRelationshipName);
|
||||
for (NSString* relationshipName = firstRelationshipName; relationshipName != nil; relationshipName = va_arg(args, NSString*)) {
|
||||
NSString* primaryKeyAttribute = va_arg(args, NSString*);
|
||||
for (NSString *relationshipName = firstRelationshipName; relationshipName != nil; relationshipName = va_arg(args, NSString *)) {
|
||||
NSString *primaryKeyAttribute = va_arg(args, NSString *);
|
||||
NSAssert(primaryKeyAttribute != nil, @"Cannot connect a relationship without an attribute containing the primary key");
|
||||
[self connectRelationship:relationshipName withObjectForPrimaryKeyAttribute:primaryKeyAttribute];
|
||||
// TODO: Raise proper exception here, argument error...
|
||||
@@ -122,23 +122,23 @@
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
- (void)connectRelationship:(NSString*)relationshipName withObjectForPrimaryKeyAttribute:(NSString*)primaryKeyAttribute whenValueOfKeyPath:(NSString*)keyPath isEqualTo:(id)value
|
||||
- (void)connectRelationship:(NSString *)relationshipName withObjectForPrimaryKeyAttribute:(NSString *)primaryKeyAttribute whenValueOfKeyPath:(NSString *)keyPath isEqualTo:(id)value
|
||||
{
|
||||
NSAssert([_relationshipToPrimaryKeyMappings objectForKey:relationshipName] == nil, @"Cannot add connect relationship %@ by primary key, a mapping already exists.", relationshipName);
|
||||
RKDynamicObjectMappingMatcher* matcher = [[RKDynamicObjectMappingMatcher alloc] initWithKey:keyPath value:value primaryKeyAttribute:primaryKeyAttribute];
|
||||
RKDynamicObjectMappingMatcher *matcher = [[RKDynamicObjectMappingMatcher alloc] initWithKey:keyPath value:value primaryKeyAttribute:primaryKeyAttribute];
|
||||
[_relationshipToPrimaryKeyMappings setObject:matcher forKey:relationshipName];
|
||||
[matcher release];
|
||||
}
|
||||
|
||||
- (void)connectRelationship:(NSString*)relationshipName withObjectForPrimaryKeyAttribute:(NSString*)primaryKeyAttribute usingEvaluationBlock:(BOOL (^)(id data))block
|
||||
- (void)connectRelationship:(NSString *)relationshipName withObjectForPrimaryKeyAttribute:(NSString *)primaryKeyAttribute usingEvaluationBlock:(BOOL (^)(id data))block
|
||||
{
|
||||
NSAssert([_relationshipToPrimaryKeyMappings objectForKey:relationshipName] == nil, @"Cannot add connect relationship %@ by primary key, a mapping already exists.", relationshipName);
|
||||
RKDynamicObjectMappingMatcher* matcher = [[RKDynamicObjectMappingMatcher alloc] initWithPrimaryKeyAttribute:primaryKeyAttribute evaluationBlock:block];
|
||||
RKDynamicObjectMappingMatcher *matcher = [[RKDynamicObjectMappingMatcher alloc] initWithPrimaryKeyAttribute:primaryKeyAttribute evaluationBlock:block];
|
||||
[_relationshipToPrimaryKeyMappings setObject:matcher forKey:relationshipName];
|
||||
[matcher release];
|
||||
}
|
||||
|
||||
- (id)defaultValueForMissingAttribute:(NSString*)attributeName
|
||||
- (id)defaultValueForMissingAttribute:(NSString *)attributeName
|
||||
{
|
||||
NSAttributeDescription *desc = [[self.entity attributesByName] valueForKey:attributeName];
|
||||
return [desc defaultValue];
|
||||
@@ -150,16 +150,16 @@
|
||||
|
||||
id object = nil;
|
||||
id primaryKeyValue = nil;
|
||||
NSString* primaryKeyAttribute;
|
||||
NSString *primaryKeyAttribute;
|
||||
|
||||
NSEntityDescription* entity = [self entity];
|
||||
RKObjectAttributeMapping* primaryKeyAttributeMapping = nil;
|
||||
NSEntityDescription *entity = [self entity];
|
||||
RKObjectAttributeMapping *primaryKeyAttributeMapping = nil;
|
||||
|
||||
primaryKeyAttribute = [self primaryKeyAttribute];
|
||||
if (primaryKeyAttribute) {
|
||||
// If a primary key has been set on the object mapping, find the attribute mapping
|
||||
// so that we can extract any existing primary key from the mappable data
|
||||
for (RKObjectAttributeMapping* attributeMapping in self.attributeMappings) {
|
||||
for (RKObjectAttributeMapping *attributeMapping in self.attributeMappings) {
|
||||
if ([attributeMapping.destinationKeyPath isEqualToString:primaryKeyAttribute]) {
|
||||
primaryKeyAttributeMapping = attributeMapping;
|
||||
break;
|
||||
@@ -171,7 +171,7 @@
|
||||
RKLogDebug(@"Detected use of nested dictionary key as primaryKey attribute...");
|
||||
primaryKeyValue = [[mappableData allKeys] lastObject];
|
||||
} else {
|
||||
NSString* keyPathForPrimaryKeyElement = primaryKeyAttributeMapping.sourceKeyPath;
|
||||
NSString *keyPathForPrimaryKeyElement = primaryKeyAttributeMapping.sourceKeyPath;
|
||||
if (keyPathForPrimaryKeyElement) {
|
||||
primaryKeyValue = [mappableData valueForKeyPath:keyPathForPrimaryKeyElement];
|
||||
} else {
|
||||
@@ -207,7 +207,7 @@
|
||||
return object;
|
||||
}
|
||||
|
||||
- (Class)classForProperty:(NSString*)propertyName
|
||||
- (Class)classForProperty:(NSString *)propertyName
|
||||
{
|
||||
Class propertyClass = [super classForProperty:propertyName];
|
||||
if (! propertyClass) {
|
||||
|
||||
@@ -34,12 +34,12 @@
|
||||
|
||||
- (void)connectRelationship:(NSString *)relationshipName
|
||||
{
|
||||
NSDictionary* relationshipsAndPrimaryKeyAttributes = [(RKManagedObjectMapping*)self.objectMapping relationshipsAndPrimaryKeyAttributes];
|
||||
NSDictionary *relationshipsAndPrimaryKeyAttributes = [(RKManagedObjectMapping *)self.objectMapping relationshipsAndPrimaryKeyAttributes];
|
||||
id primaryKeyObject = [relationshipsAndPrimaryKeyAttributes objectForKey:relationshipName];
|
||||
NSString* primaryKeyAttribute = nil;
|
||||
NSString *primaryKeyAttribute = nil;
|
||||
if ([primaryKeyObject isKindOfClass:[RKDynamicObjectMappingMatcher class]]) {
|
||||
RKLogTrace(@"Found a dynamic matcher attempting to connect relationshipName: %@", relationshipName);
|
||||
RKDynamicObjectMappingMatcher* matcher = (RKDynamicObjectMappingMatcher*)primaryKeyObject;
|
||||
RKDynamicObjectMappingMatcher *matcher = (RKDynamicObjectMappingMatcher *)primaryKeyObject;
|
||||
if ([matcher isMatchForData:self.destinationObject]) {
|
||||
primaryKeyAttribute = matcher.primaryKeyAttribute;
|
||||
RKLogTrace(@"Dynamic matched succeeded. Proceeding to connect relationshipName '%@' using primaryKeyAttribute '%@'", relationshipName, primaryKeyAttribute);
|
||||
@@ -48,11 +48,11 @@
|
||||
return;
|
||||
}
|
||||
} else if ([primaryKeyObject isKindOfClass:[NSString class]]) {
|
||||
primaryKeyAttribute = (NSString*)primaryKeyObject;
|
||||
primaryKeyAttribute = (NSString *)primaryKeyObject;
|
||||
}
|
||||
NSAssert(primaryKeyAttribute, @"Cannot connect relationship without primaryKeyAttribute");
|
||||
|
||||
RKObjectRelationshipMapping* relationshipMapping = [self.objectMapping mappingForRelationship:relationshipName];
|
||||
RKObjectRelationshipMapping *relationshipMapping = [self.objectMapping mappingForRelationship:relationshipName];
|
||||
RKObjectMappingDefinition *mapping = relationshipMapping.mapping;
|
||||
NSAssert(mapping, @"Attempted to connect relationship for keyPath '%@' without a relationship mapping defined.");
|
||||
if (! [mapping isKindOfClass:[RKObjectMapping class]]) {
|
||||
@@ -63,7 +63,7 @@
|
||||
NSAssert(relationshipMapping, @"Unable to find relationship mapping '%@' to connect by primaryKey", relationshipName);
|
||||
NSAssert([relationshipMapping isKindOfClass:[RKObjectRelationshipMapping class]], @"Expected mapping for %@ to be a relationship mapping", relationshipName);
|
||||
NSAssert([relationshipMapping.mapping isKindOfClass:[RKManagedObjectMapping class]], @"Can only connect RKManagedObjectMapping relationships");
|
||||
NSString* primaryKeyAttributeOfRelatedObject = [(RKManagedObjectMapping*)objectMapping primaryKeyAttribute];
|
||||
NSString *primaryKeyAttributeOfRelatedObject = [(RKManagedObjectMapping *)objectMapping primaryKeyAttribute];
|
||||
NSAssert(primaryKeyAttributeOfRelatedObject, @"Cannot connect relationship: mapping for %@ has no primary key attribute specified", NSStringFromClass(objectMapping.objectClass));
|
||||
id valueOfLocalPrimaryKeyAttribute = [self.destinationObject valueForKey:primaryKeyAttribute];
|
||||
if (valueOfLocalPrimaryKeyAttribute) {
|
||||
@@ -73,9 +73,9 @@
|
||||
|
||||
// Implemented for issue 284 - https://github.com/RestKit/RestKit/issues/284
|
||||
relatedObject = [NSMutableSet set];
|
||||
NSObject<RKManagedObjectCaching> *cache = [[(RKManagedObjectMapping*)[self objectMapping] objectStore] cacheStrategy];
|
||||
NSObject<RKManagedObjectCaching> *cache = [[(RKManagedObjectMapping *)[self objectMapping] objectStore] cacheStrategy];
|
||||
for (id foreignKey in valueOfLocalPrimaryKeyAttribute) {
|
||||
id searchResult = [cache findInstanceOfEntity:objectMapping.entity withPrimaryKeyAttribute:primaryKeyAttributeOfRelatedObject value:foreignKey inManagedObjectContext:[[(RKManagedObjectMapping*)[self objectMapping] objectStore] managedObjectContextForCurrentThread]];
|
||||
id searchResult = [cache findInstanceOfEntity:objectMapping.entity withPrimaryKeyAttribute:primaryKeyAttributeOfRelatedObject value:foreignKey inManagedObjectContext:[[(RKManagedObjectMapping *)[self objectMapping] objectStore] managedObjectContextForCurrentThread]];
|
||||
if (searchResult) {
|
||||
[relatedObject addObject:searchResult];
|
||||
}
|
||||
@@ -84,7 +84,7 @@
|
||||
RKLogTrace(@"Connecting has-one relationship at keyPath '%@' to object with primaryKey attribute '%@'", relationshipName, primaryKeyAttributeOfRelatedObject);
|
||||
|
||||
// Normal foreign key
|
||||
NSObject<RKManagedObjectCaching> *cache = [[(RKManagedObjectMapping*)[self objectMapping] objectStore] cacheStrategy];
|
||||
NSObject<RKManagedObjectCaching> *cache = [[(RKManagedObjectMapping *)[self objectMapping] objectStore] cacheStrategy];
|
||||
relatedObject = [cache findInstanceOfEntity:objectMapping.entity withPrimaryKeyAttribute:primaryKeyAttributeOfRelatedObject value:valueOfLocalPrimaryKeyAttribute inManagedObjectContext:[self.destinationObject managedObjectContext]];
|
||||
}
|
||||
if (relatedObject) {
|
||||
@@ -105,9 +105,9 @@
|
||||
|
||||
- (void)connectRelationships
|
||||
{
|
||||
NSDictionary* relationshipsAndPrimaryKeyAttributes = [(RKManagedObjectMapping *)self.objectMapping relationshipsAndPrimaryKeyAttributes];
|
||||
NSDictionary *relationshipsAndPrimaryKeyAttributes = [(RKManagedObjectMapping *)self.objectMapping relationshipsAndPrimaryKeyAttributes];
|
||||
RKLogTrace(@"relationshipsAndPrimaryKeyAttributes: %@", relationshipsAndPrimaryKeyAttributes);
|
||||
for (NSString* relationshipName in relationshipsAndPrimaryKeyAttributes) {
|
||||
for (NSString *relationshipName in relationshipsAndPrimaryKeyAttributes) {
|
||||
if (self.queue) {
|
||||
RKLogTrace(@"Enqueueing relationship connection using operation queue");
|
||||
__block RKManagedObjectMappingOperation *selfRef = self;
|
||||
|
||||
@@ -40,12 +40,12 @@
|
||||
* Normalize and tokenize the provided string into an NSArray.
|
||||
* Note that returned value may contain entries of empty strings.
|
||||
*/
|
||||
+ (NSArray*)tokenizedNormalizedString:(NSString*)string;
|
||||
+ (NSArray *)tokenizedNormalizedString:(NSString *)string;
|
||||
|
||||
/**
|
||||
* Generate a predicate for the supplied search term against
|
||||
* searchableAttributes (defined for an RKSearchableManagedObject)
|
||||
*/
|
||||
- (NSPredicate*)predicateForSearch:(NSString*)searchText;
|
||||
- (NSPredicate *)predicateForSearch:(NSString *)searchText;
|
||||
|
||||
@end
|
||||
|
||||
@@ -28,13 +28,13 @@
|
||||
|
||||
@implementation RKManagedObjectSearchEngine
|
||||
|
||||
static NSMutableCharacterSet* __removeSet;
|
||||
static NSMutableCharacterSet *__removeSet;
|
||||
|
||||
@synthesize mode = _mode;
|
||||
|
||||
+ (id)searchEngine
|
||||
{
|
||||
RKManagedObjectSearchEngine* searchEngine = [[[RKManagedObjectSearchEngine alloc] init] autorelease];
|
||||
RKManagedObjectSearchEngine *searchEngine = [[[RKManagedObjectSearchEngine alloc] init] autorelease];
|
||||
return searchEngine;
|
||||
}
|
||||
|
||||
@@ -50,10 +50,10 @@ static NSMutableCharacterSet* __removeSet;
|
||||
#pragma mark -
|
||||
#pragma mark Private
|
||||
|
||||
- (NSPredicate*)predicateForSearch:(NSArray*)searchTerms compoundSelector:(SEL)selector
|
||||
- (NSPredicate *)predicateForSearch:(NSArray *)searchTerms compoundSelector:(SEL)selector
|
||||
{
|
||||
NSMutableArray* termPredicates = [NSMutableArray array];
|
||||
for (NSString* searchTerm in searchTerms) {
|
||||
NSMutableArray *termPredicates = [NSMutableArray array];
|
||||
for (NSString *searchTerm in searchTerms) {
|
||||
[termPredicates addObject:
|
||||
[NSPredicate predicateWithFormat:@"(ANY searchWords.word beginswith %@)", searchTerm]];
|
||||
}
|
||||
@@ -63,28 +63,28 @@ static NSMutableCharacterSet* __removeSet;
|
||||
#pragma mark -
|
||||
#pragma mark Public
|
||||
|
||||
+ (NSArray*)tokenizedNormalizedString:(NSString*)string
|
||||
+ (NSArray *)tokenizedNormalizedString:(NSString *)string
|
||||
{
|
||||
if (__removeSet == nil) {
|
||||
NSMutableCharacterSet* removeSet = [[NSCharacterSet alphanumericCharacterSet] mutableCopy];
|
||||
NSMutableCharacterSet *removeSet = [[NSCharacterSet alphanumericCharacterSet] mutableCopy];
|
||||
[removeSet formUnionWithCharacterSet:[NSCharacterSet whitespaceCharacterSet]];
|
||||
[removeSet invert];
|
||||
__removeSet = removeSet;
|
||||
}
|
||||
|
||||
NSString* scannerString = [[[[string lowercaseString] decomposedStringWithCanonicalMapping]
|
||||
NSString *scannerString = [[[[string lowercaseString] decomposedStringWithCanonicalMapping]
|
||||
stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]
|
||||
stringByReplacingOccurrencesOfString:@"-" withString:@" "];
|
||||
|
||||
NSArray* tokens = [[[scannerString componentsSeparatedByCharactersInSet:__removeSet]
|
||||
NSArray *tokens = [[[scannerString componentsSeparatedByCharactersInSet:__removeSet]
|
||||
componentsJoinedByString:@""] componentsSeparatedByString:@" "];
|
||||
return tokens;
|
||||
}
|
||||
|
||||
- (NSPredicate*)predicateForSearch:(NSString*)searchText
|
||||
- (NSPredicate *)predicateForSearch:(NSString *)searchText
|
||||
{
|
||||
NSString* searchQuery = [searchText copy];
|
||||
NSArray* searchTerms = [RKManagedObjectSearchEngine tokenizedNormalizedString:searchQuery];
|
||||
NSString *searchQuery = [searchText copy];
|
||||
NSArray *searchTerms = [RKManagedObjectSearchEngine tokenizedNormalizedString:searchQuery];
|
||||
[searchQuery release];
|
||||
|
||||
if ([searchTerms count] == 0) {
|
||||
|
||||
@@ -21,13 +21,13 @@
|
||||
#import "ObjectMapping.h"
|
||||
|
||||
// The default seed database filename. Used when the object store has not been initialized
|
||||
extern NSString* const RKDefaultSeedDatabaseFileName;
|
||||
extern NSString * const RKDefaultSeedDatabaseFileName;
|
||||
|
||||
@protocol RKManagedObjectSeederDelegate
|
||||
@required
|
||||
|
||||
// Invoked when the seeder creates a new object
|
||||
- (void)didSeedObject:(NSManagedObject*)object fromFile:(NSString*)fileName;
|
||||
- (void)didSeedObject:(NSManagedObject *)object fromFile:(NSString *)fileName;
|
||||
@end
|
||||
|
||||
/**
|
||||
@@ -39,36 +39,36 @@ extern NSString* const RKDefaultSeedDatabaseFileName;
|
||||
* data immediately available for use within Core Data.
|
||||
*/
|
||||
@interface RKManagedObjectSeeder : NSObject {
|
||||
RKObjectManager* _manager;
|
||||
NSObject<RKManagedObjectSeederDelegate>* _delegate;
|
||||
RKObjectManager *_manager;
|
||||
NSObject<RKManagedObjectSeederDelegate> *_delegate;
|
||||
}
|
||||
|
||||
// Delegate for seeding operations
|
||||
@property (nonatomic, assign) NSObject<RKManagedObjectSeederDelegate>* delegate;
|
||||
@property (nonatomic, assign) NSObject<RKManagedObjectSeederDelegate> *delegate;
|
||||
|
||||
// Path to the generated seed database on disk
|
||||
@property (nonatomic, readonly) NSString* pathToSeedDatabase;
|
||||
@property (nonatomic, readonly) NSString *pathToSeedDatabase;
|
||||
|
||||
/**
|
||||
* Generates a seed database using an object manager and a null terminated list of files. Exits
|
||||
* the seeding process and outputs an informational message
|
||||
*/
|
||||
+ (void)generateSeedDatabaseWithObjectManager:(RKObjectManager*)objectManager fromFiles:(NSString*)fileName, ...;
|
||||
+ (void)generateSeedDatabaseWithObjectManager:(RKObjectManager *)objectManager fromFiles:(NSString *)fileName, ...;
|
||||
|
||||
/**
|
||||
* Returns an object seeder ready to begin seeding. Requires a fully configured instance of an object manager.
|
||||
*/
|
||||
+ (RKManagedObjectSeeder*)objectSeederWithObjectManager:(RKObjectManager*)objectManager;
|
||||
+ (RKManagedObjectSeeder *)objectSeederWithObjectManager:(RKObjectManager *)objectManager;
|
||||
|
||||
/**
|
||||
* Seed the database with objects from the specified file(s). The list must be terminated by nil
|
||||
*/
|
||||
- (void)seedObjectsFromFiles:(NSString*)fileName, ...;
|
||||
- (void)seedObjectsFromFiles:(NSString *)fileName, ...;
|
||||
|
||||
/**
|
||||
* Seed the database with objects from the specified file using the supplied object mapping.
|
||||
*/
|
||||
- (void)seedObjectsFromFile:(NSString*)fileName withObjectMapping:(RKObjectMapping*)nilOrObjectMapping;
|
||||
- (void)seedObjectsFromFile:(NSString *)fileName withObjectMapping:(RKObjectMapping *)nilOrObjectMapping;
|
||||
|
||||
/**
|
||||
* Seed the database with objects from the specified file, from the specified bundle, using the supplied object mapping.
|
||||
|
||||
@@ -32,42 +32,42 @@
|
||||
#define RKLogComponent lcl_cRestKitCoreData
|
||||
|
||||
@interface RKManagedObjectSeeder (Private)
|
||||
- (id)initWithObjectManager:(RKObjectManager*)manager;
|
||||
- (void)seedObjectsFromFileNames:(NSArray*)fileNames;
|
||||
- (id)initWithObjectManager:(RKObjectManager *)manager;
|
||||
- (void)seedObjectsFromFileNames:(NSArray *)fileNames;
|
||||
@end
|
||||
|
||||
NSString* const RKDefaultSeedDatabaseFileName = @"RKSeedDatabase.sqlite";
|
||||
NSString * const RKDefaultSeedDatabaseFileName = @"RKSeedDatabase.sqlite";
|
||||
|
||||
@implementation RKManagedObjectSeeder
|
||||
|
||||
@synthesize delegate = _delegate;
|
||||
|
||||
+ (void)generateSeedDatabaseWithObjectManager:(RKObjectManager*)objectManager fromFiles:(NSString*)firstFileName, ...
|
||||
+ (void)generateSeedDatabaseWithObjectManager:(RKObjectManager *)objectManager fromFiles:(NSString *)firstFileName, ...
|
||||
{
|
||||
RKManagedObjectSeeder* seeder = [RKManagedObjectSeeder objectSeederWithObjectManager:objectManager];
|
||||
RKManagedObjectSeeder *seeder = [RKManagedObjectSeeder objectSeederWithObjectManager:objectManager];
|
||||
|
||||
va_list args;
|
||||
va_start(args, firstFileName);
|
||||
NSMutableArray* fileNames = [NSMutableArray array];
|
||||
for (NSString* fileName = firstFileName; fileName != nil; fileName = va_arg(args, id)) {
|
||||
NSMutableArray *fileNames = [NSMutableArray array];
|
||||
for (NSString *fileName = firstFileName; fileName != nil; fileName = va_arg(args, id)) {
|
||||
[fileNames addObject:fileName];
|
||||
}
|
||||
va_end(args);
|
||||
|
||||
// Seed the files
|
||||
for (NSString* fileName in fileNames) {
|
||||
for (NSString *fileName in fileNames) {
|
||||
[seeder seedObjectsFromFile:fileName withObjectMapping:nil];
|
||||
}
|
||||
|
||||
[seeder finalizeSeedingAndExit];
|
||||
}
|
||||
|
||||
+ (RKManagedObjectSeeder*)objectSeederWithObjectManager:(RKObjectManager*)objectManager
|
||||
+ (RKManagedObjectSeeder *)objectSeederWithObjectManager:(RKObjectManager *)objectManager
|
||||
{
|
||||
return [[[RKManagedObjectSeeder alloc] initWithObjectManager:objectManager] autorelease];
|
||||
}
|
||||
|
||||
- (id)initWithObjectManager:(RKObjectManager*)manager
|
||||
- (id)initWithObjectManager:(RKObjectManager *)manager
|
||||
{
|
||||
self = [self init];
|
||||
if (self) {
|
||||
@@ -91,44 +91,44 @@ NSString* const RKDefaultSeedDatabaseFileName = @"RKSeedDatabase.sqlite";
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSString*)pathToSeedDatabase
|
||||
- (NSString *)pathToSeedDatabase
|
||||
{
|
||||
return _manager.objectStore.pathToStoreFile;
|
||||
}
|
||||
|
||||
- (void)seedObjectsFromFiles:(NSString*)firstFileName, ...
|
||||
- (void)seedObjectsFromFiles:(NSString *)firstFileName, ...
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, firstFileName);
|
||||
NSMutableArray* fileNames = [NSMutableArray array];
|
||||
for (NSString* fileName = firstFileName; fileName != nil; fileName = va_arg(args, id)) {
|
||||
NSMutableArray *fileNames = [NSMutableArray array];
|
||||
for (NSString *fileName = firstFileName; fileName != nil; fileName = va_arg(args, id)) {
|
||||
[fileNames addObject:fileName];
|
||||
}
|
||||
va_end(args);
|
||||
|
||||
for (NSString* fileName in fileNames) {
|
||||
for (NSString *fileName in fileNames) {
|
||||
[self seedObjectsFromFile:fileName withObjectMapping:nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)seedObjectsFromFile:(NSString*)fileName withObjectMapping:(RKObjectMapping *)nilOrObjectMapping
|
||||
- (void)seedObjectsFromFile:(NSString *)fileName withObjectMapping:(RKObjectMapping *)nilOrObjectMapping
|
||||
{
|
||||
[self seedObjectsFromFile:fileName withObjectMapping:nilOrObjectMapping bundle:nil];
|
||||
}
|
||||
|
||||
- (void)seedObjectsFromFile:(NSString *)fileName withObjectMapping:(RKObjectMapping *)nilOrObjectMapping bundle:(NSBundle *)nilOrBundle
|
||||
{
|
||||
NSError* error = nil;
|
||||
NSError *error = nil;
|
||||
|
||||
if (nilOrBundle == nil) {
|
||||
nilOrBundle = [NSBundle mainBundle];
|
||||
}
|
||||
|
||||
NSString* filePath = [nilOrBundle pathForResource:fileName ofType:nil];
|
||||
NSString* payload = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:&error];
|
||||
NSString *filePath = [nilOrBundle pathForResource:fileName ofType:nil];
|
||||
NSString *payload = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:&error];
|
||||
|
||||
if (payload) {
|
||||
NSString* MIMEType = [fileName MIMETypeForPathExtension];
|
||||
NSString *MIMEType = [fileName MIMETypeForPathExtension];
|
||||
if (MIMEType == nil) {
|
||||
// Default the MIME type to the value of the Accept header if we couldn't detect it...
|
||||
MIMEType = _manager.acceptMIMEType;
|
||||
@@ -138,7 +138,7 @@ NSString* const RKDefaultSeedDatabaseFileName = @"RKSeedDatabase.sqlite";
|
||||
id parsedData = [parser objectFromString:payload error:&error];
|
||||
NSAssert(parsedData, @"Cannot perform object load without data for mapping");
|
||||
|
||||
RKObjectMappingProvider* mappingProvider = nil;
|
||||
RKObjectMappingProvider *mappingProvider = nil;
|
||||
if (nilOrObjectMapping) {
|
||||
mappingProvider = [[RKObjectMappingProvider new] autorelease];
|
||||
[mappingProvider setMapping:nilOrObjectMapping forKeyPath:@""];
|
||||
@@ -146,19 +146,19 @@ NSString* const RKDefaultSeedDatabaseFileName = @"RKSeedDatabase.sqlite";
|
||||
mappingProvider = _manager.mappingProvider;
|
||||
}
|
||||
|
||||
RKObjectMapper* mapper = [RKObjectMapper mapperWithObject:parsedData mappingProvider:mappingProvider];
|
||||
RKObjectMappingResult* result = [mapper performMapping];
|
||||
RKObjectMapper *mapper = [RKObjectMapper mapperWithObject:parsedData mappingProvider:mappingProvider];
|
||||
RKObjectMappingResult *result = [mapper performMapping];
|
||||
if (result == nil) {
|
||||
RKLogError(@"Database seeding from file '%@' failed due to object mapping errors: %@", fileName, mapper.errors);
|
||||
return;
|
||||
}
|
||||
|
||||
NSArray* mappedObjects = [result asCollection];
|
||||
NSArray *mappedObjects = [result asCollection];
|
||||
NSAssert1([mappedObjects isKindOfClass:[NSArray class]], @"Expected an NSArray of objects, got %@", mappedObjects);
|
||||
|
||||
// Inform the delegate
|
||||
if (self.delegate) {
|
||||
for (NSManagedObject* object in mappedObjects) {
|
||||
for (NSManagedObject *object in mappedObjects) {
|
||||
[self.delegate didSeedObject:object fromFile:fileName];
|
||||
}
|
||||
}
|
||||
@@ -177,10 +177,10 @@ NSString* const RKDefaultSeedDatabaseFileName = @"RKSeedDatabase.sqlite";
|
||||
RKLogError(@"[RestKit] RKManagedObjectSeeder: Error saving object context: %@", [error localizedDescription]);
|
||||
}
|
||||
|
||||
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
||||
NSString* basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
|
||||
NSString* storeFileName = [[_manager objectStore] storeFilename];
|
||||
NSString* destinationPath = [basePath stringByAppendingPathComponent:storeFileName];
|
||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
||||
NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
|
||||
NSString *storeFileName = [[_manager objectStore] storeFilename];
|
||||
NSString *destinationPath = [basePath stringByAppendingPathComponent:storeFileName];
|
||||
RKLogInfo(@"A seeded database has been generated at '%@'. "
|
||||
@"Please execute `open \"%@\"` in your Terminal and copy %@ to your app. Be sure to add the seed database to your \"Copy Resources\" build phase.",
|
||||
destinationPath, basePath, storeFileName);
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
/**
|
||||
* Notifications
|
||||
*/
|
||||
extern NSString* const RKManagedObjectStoreDidFailSaveNotification;
|
||||
extern NSString * const RKManagedObjectStoreDidFailSaveNotification;
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -47,25 +47,25 @@ extern NSString* const RKManagedObjectStoreDidFailSaveNotification;
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@interface RKManagedObjectStore : NSObject {
|
||||
NSObject<RKManagedObjectStoreDelegate>* _delegate;
|
||||
NSString* _storeFilename;
|
||||
NSString* _pathToStoreFile;
|
||||
NSManagedObjectModel* _managedObjectModel;
|
||||
NSPersistentStoreCoordinator* _persistentStoreCoordinator;
|
||||
NSObject<RKManagedObjectStoreDelegate> *_delegate;
|
||||
NSString *_storeFilename;
|
||||
NSString *_pathToStoreFile;
|
||||
NSManagedObjectModel *_managedObjectModel;
|
||||
NSPersistentStoreCoordinator *_persistentStoreCoordinator;
|
||||
}
|
||||
|
||||
// The delegate for this object store
|
||||
@property (nonatomic, assign) NSObject<RKManagedObjectStoreDelegate>* delegate;
|
||||
@property (nonatomic, assign) NSObject<RKManagedObjectStoreDelegate> *delegate;
|
||||
|
||||
// The filename of the database backing this object store
|
||||
@property (nonatomic, readonly) NSString* storeFilename;
|
||||
@property (nonatomic, readonly) NSString *storeFilename;
|
||||
|
||||
// The full path to the database backing this object store
|
||||
@property (nonatomic, readonly) NSString* pathToStoreFile;
|
||||
@property (nonatomic, readonly) NSString *pathToStoreFile;
|
||||
|
||||
// Core Data
|
||||
@property (nonatomic, readonly) NSManagedObjectModel* managedObjectModel;
|
||||
@property (nonatomic, readonly) NSPersistentStoreCoordinator* persistentStoreCoordinator;
|
||||
@property (nonatomic, readonly) NSManagedObjectModel *managedObjectModel;
|
||||
@property (nonatomic, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;
|
||||
|
||||
///-----------------------------------------------------------------------------
|
||||
/// @name Accessing the Default Object Store
|
||||
@@ -105,7 +105,7 @@ extern NSString* const RKManagedObjectStoreDidFailSaveNotification;
|
||||
/**
|
||||
* Initialize a new managed object store with a SQLite database with the filename specified
|
||||
*/
|
||||
+ (RKManagedObjectStore*)objectStoreWithStoreFilename:(NSString*)storeFilename;
|
||||
+ (RKManagedObjectStore *)objectStoreWithStoreFilename:(NSString *)storeFilename;
|
||||
|
||||
/**
|
||||
* Initialize a new managed object store backed by a SQLite database with the specified filename.
|
||||
@@ -113,7 +113,7 @@ extern NSString* const RKManagedObjectStoreDidFailSaveNotification;
|
||||
* copying the seed database from the main bundle. If the managed object model provided is nil,
|
||||
* all models will be merged from the main bundle for you.
|
||||
*/
|
||||
+ (RKManagedObjectStore*)objectStoreWithStoreFilename:(NSString *)storeFilename usingSeedDatabaseName:(NSString *)nilOrNameOfSeedDatabaseInMainBundle managedObjectModel:(NSManagedObjectModel*)nilOrManagedObjectModel delegate:(id)delegate;
|
||||
+ (RKManagedObjectStore *)objectStoreWithStoreFilename:(NSString *)storeFilename usingSeedDatabaseName:(NSString *)nilOrNameOfSeedDatabaseInMainBundle managedObjectModel:(NSManagedObjectModel *)nilOrManagedObjectModel delegate:(id)delegate;
|
||||
|
||||
/**
|
||||
* Initialize a new managed object store backed by a SQLite database with the specified filename,
|
||||
@@ -122,13 +122,13 @@ extern NSString* const RKManagedObjectStoreDidFailSaveNotification;
|
||||
* the store by copying the seed database from the main bundle. If the managed object model
|
||||
* provided is nil, all models will be merged from the main bundle for you.
|
||||
*/
|
||||
+ (RKManagedObjectStore*)objectStoreWithStoreFilename:(NSString *)storeFilename inDirectory:(NSString *)directory usingSeedDatabaseName:(NSString *)nilOrNameOfSeedDatabaseInMainBundle managedObjectModel:(NSManagedObjectModel*)nilOrManagedObjectModel delegate:(id)delegate;
|
||||
+ (RKManagedObjectStore *)objectStoreWithStoreFilename:(NSString *)storeFilename inDirectory:(NSString *)directory usingSeedDatabaseName:(NSString *)nilOrNameOfSeedDatabaseInMainBundle managedObjectModel:(NSManagedObjectModel *)nilOrManagedObjectModel delegate:(id)delegate;
|
||||
|
||||
/**
|
||||
* Initialize a new managed object store with a SQLite database with the filename specified
|
||||
* @deprecated
|
||||
*/
|
||||
- (id)initWithStoreFilename:(NSString*)storeFilename DEPRECATED_ATTRIBUTE;
|
||||
- (id)initWithStoreFilename:(NSString *)storeFilename DEPRECATED_ATTRIBUTE;
|
||||
|
||||
/**
|
||||
* Save the current contents of the managed object store
|
||||
@@ -145,13 +145,13 @@ extern NSString* const RKManagedObjectStoreDidFailSaveNotification;
|
||||
/**
|
||||
* Retrieves a model object from the appropriate context using the objectId
|
||||
*/
|
||||
- (NSManagedObject*)objectWithID:(NSManagedObjectID*)objectID;
|
||||
- (NSManagedObject *)objectWithID:(NSManagedObjectID *)objectID;
|
||||
|
||||
/**
|
||||
* Retrieves a array of model objects from the appropriate context using
|
||||
* an array of NSManagedObjectIDs
|
||||
*/
|
||||
- (NSArray*)objectsWithIDs:(NSArray*)objectIDs;
|
||||
- (NSArray *)objectsWithIDs:(NSArray *)objectIDs;
|
||||
|
||||
///-----------------------------------------------------------------------------
|
||||
/// @name Retrieving Managed Object Contexts
|
||||
|
||||
@@ -35,19 +35,19 @@
|
||||
#undef RKLogComponent
|
||||
#define RKLogComponent lcl_cRestKitCoreData
|
||||
|
||||
NSString* const RKManagedObjectStoreDidFailSaveNotification = @"RKManagedObjectStoreDidFailSaveNotification";
|
||||
static NSString* const RKManagedObjectStoreThreadDictionaryContextKey = @"RKManagedObjectStoreThreadDictionaryContextKey";
|
||||
static NSString* const RKManagedObjectStoreThreadDictionaryEntityCacheKey = @"RKManagedObjectStoreThreadDictionaryEntityCacheKey";
|
||||
NSString * const RKManagedObjectStoreDidFailSaveNotification = @"RKManagedObjectStoreDidFailSaveNotification";
|
||||
static NSString * const RKManagedObjectStoreThreadDictionaryContextKey = @"RKManagedObjectStoreThreadDictionaryContextKey";
|
||||
static NSString * const RKManagedObjectStoreThreadDictionaryEntityCacheKey = @"RKManagedObjectStoreThreadDictionaryEntityCacheKey";
|
||||
|
||||
static RKManagedObjectStore *defaultObjectStore = nil;
|
||||
|
||||
@interface RKManagedObjectStore ()
|
||||
@property (nonatomic, retain, readwrite) NSManagedObjectContext *primaryManagedObjectContext;
|
||||
|
||||
- (id)initWithStoreFilename:(NSString *)storeFilename inDirectory:(NSString *)nilOrDirectoryPath usingSeedDatabaseName:(NSString *)nilOrNameOfSeedDatabaseInMainBundle managedObjectModel:(NSManagedObjectModel*)nilOrManagedObjectModel delegate:(id)delegate;
|
||||
- (id)initWithStoreFilename:(NSString *)storeFilename inDirectory:(NSString *)nilOrDirectoryPath usingSeedDatabaseName:(NSString *)nilOrNameOfSeedDatabaseInMainBundle managedObjectModel:(NSManagedObjectModel *)nilOrManagedObjectModel delegate:(id)delegate;
|
||||
- (void)createPersistentStoreCoordinator;
|
||||
- (void)createStoreIfNecessaryUsingSeedDatabase:(NSString*)seedDatabase;
|
||||
- (NSManagedObjectContext*)newManagedObjectContext;
|
||||
- (void)createStoreIfNecessaryUsingSeedDatabase:(NSString *)seedDatabase;
|
||||
- (NSManagedObjectContext *)newManagedObjectContext;
|
||||
@end
|
||||
|
||||
@implementation RKManagedObjectStore
|
||||
@@ -76,8 +76,8 @@ static RKManagedObjectStore *defaultObjectStore = nil;
|
||||
|
||||
+ (void)deleteStoreAtPath:(NSString *)path
|
||||
{
|
||||
NSURL* storeURL = [NSURL fileURLWithPath:path];
|
||||
NSError* error = nil;
|
||||
NSURL *storeURL = [NSURL fileURLWithPath:path];
|
||||
NSError *error = nil;
|
||||
if ([[NSFileManager defaultManager] fileExistsAtPath:storeURL.path]) {
|
||||
if (! [[NSFileManager defaultManager] removeItemAtPath:storeURL.path error:&error]) {
|
||||
NSAssert(NO, @"Managed object store failed to delete persistent store : %@", error);
|
||||
@@ -93,27 +93,27 @@ static RKManagedObjectStore *defaultObjectStore = nil;
|
||||
[self deleteStoreAtPath:path];
|
||||
}
|
||||
|
||||
+ (RKManagedObjectStore*)objectStoreWithStoreFilename:(NSString*)storeFilename
|
||||
+ (RKManagedObjectStore *)objectStoreWithStoreFilename:(NSString *)storeFilename
|
||||
{
|
||||
return [self objectStoreWithStoreFilename:storeFilename usingSeedDatabaseName:nil managedObjectModel:nil delegate:nil];
|
||||
}
|
||||
|
||||
+ (RKManagedObjectStore*)objectStoreWithStoreFilename:(NSString *)storeFilename usingSeedDatabaseName:(NSString *)nilOrNameOfSeedDatabaseInMainBundle managedObjectModel:(NSManagedObjectModel*)nilOrManagedObjectModel delegate:(id)delegate
|
||||
+ (RKManagedObjectStore *)objectStoreWithStoreFilename:(NSString *)storeFilename usingSeedDatabaseName:(NSString *)nilOrNameOfSeedDatabaseInMainBundle managedObjectModel:(NSManagedObjectModel *)nilOrManagedObjectModel delegate:(id)delegate
|
||||
{
|
||||
return [[[self alloc] initWithStoreFilename:storeFilename inDirectory:nil usingSeedDatabaseName:nilOrNameOfSeedDatabaseInMainBundle managedObjectModel:nilOrManagedObjectModel delegate:delegate] autorelease];
|
||||
}
|
||||
|
||||
+ (RKManagedObjectStore*)objectStoreWithStoreFilename:(NSString *)storeFilename inDirectory:(NSString *)directory usingSeedDatabaseName:(NSString *)nilOrNameOfSeedDatabaseInMainBundle managedObjectModel:(NSManagedObjectModel*)nilOrManagedObjectModel delegate:(id)delegate
|
||||
+ (RKManagedObjectStore *)objectStoreWithStoreFilename:(NSString *)storeFilename inDirectory:(NSString *)directory usingSeedDatabaseName:(NSString *)nilOrNameOfSeedDatabaseInMainBundle managedObjectModel:(NSManagedObjectModel *)nilOrManagedObjectModel delegate:(id)delegate
|
||||
{
|
||||
return [[[self alloc] initWithStoreFilename:storeFilename inDirectory:directory usingSeedDatabaseName:nilOrNameOfSeedDatabaseInMainBundle managedObjectModel:nilOrManagedObjectModel delegate:delegate] autorelease];
|
||||
}
|
||||
|
||||
- (id)initWithStoreFilename:(NSString*)storeFilename
|
||||
- (id)initWithStoreFilename:(NSString *)storeFilename
|
||||
{
|
||||
return [self initWithStoreFilename:storeFilename inDirectory:nil usingSeedDatabaseName:nil managedObjectModel:nil delegate:nil];
|
||||
}
|
||||
|
||||
- (id)initWithStoreFilename:(NSString *)storeFilename inDirectory:(NSString *)nilOrDirectoryPath usingSeedDatabaseName:(NSString *)nilOrNameOfSeedDatabaseInMainBundle managedObjectModel:(NSManagedObjectModel*)nilOrManagedObjectModel delegate:(id)delegate
|
||||
- (id)initWithStoreFilename:(NSString *)storeFilename inDirectory:(NSString *)nilOrDirectoryPath usingSeedDatabaseName:(NSString *)nilOrNameOfSeedDatabaseInMainBundle managedObjectModel:(NSManagedObjectModel *)nilOrManagedObjectModel delegate:(id)delegate
|
||||
{
|
||||
self = [self init];
|
||||
if (self) {
|
||||
@@ -134,7 +134,7 @@ static RKManagedObjectStore *defaultObjectStore = nil;
|
||||
// NOTE: allBundles permits Core Data setup in unit tests
|
||||
nilOrManagedObjectModel = [NSManagedObjectModel mergedModelFromBundles:[NSBundle allBundles]];
|
||||
}
|
||||
NSMutableArray* allManagedObjectModels = [NSMutableArray arrayWithObject:nilOrManagedObjectModel];
|
||||
NSMutableArray *allManagedObjectModels = [NSMutableArray arrayWithObject:nilOrManagedObjectModel];
|
||||
_managedObjectModel = [[NSManagedObjectModel modelByMergingModels:allManagedObjectModels] retain];
|
||||
_delegate = delegate;
|
||||
|
||||
@@ -161,7 +161,7 @@ static RKManagedObjectStore *defaultObjectStore = nil;
|
||||
|
||||
- (void)setThreadLocalObject:(id)value forKey:(id)key
|
||||
{
|
||||
NSMutableDictionary* threadDictionary = [[NSThread currentThread] threadDictionary];
|
||||
NSMutableDictionary *threadDictionary = [[NSThread currentThread] threadDictionary];
|
||||
NSString *objectStoreKey = [NSString stringWithFormat:@"RKManagedObjectStore_%p", self];
|
||||
if (! [threadDictionary valueForKey:objectStoreKey]) {
|
||||
[threadDictionary setValue:[NSMutableDictionary dictionary] forKey:objectStoreKey];
|
||||
@@ -172,7 +172,7 @@ static RKManagedObjectStore *defaultObjectStore = nil;
|
||||
|
||||
- (id)threadLocalObjectForKey:(id)key
|
||||
{
|
||||
NSMutableDictionary* threadDictionary = [[NSThread currentThread] threadDictionary];
|
||||
NSMutableDictionary *threadDictionary = [[NSThread currentThread] threadDictionary];
|
||||
NSString *objectStoreKey = [NSString stringWithFormat:@"RKManagedObjectStore_%p", self];
|
||||
if (! [threadDictionary valueForKey:objectStoreKey]) {
|
||||
[threadDictionary setObject:[NSMutableDictionary dictionary] forKey:objectStoreKey];
|
||||
@@ -183,7 +183,7 @@ static RKManagedObjectStore *defaultObjectStore = nil;
|
||||
|
||||
- (void)removeThreadLocalObjectForKey:(id)key
|
||||
{
|
||||
NSMutableDictionary* threadDictionary = [[NSThread currentThread] threadDictionary];
|
||||
NSMutableDictionary *threadDictionary = [[NSThread currentThread] threadDictionary];
|
||||
NSString *objectStoreKey = [NSString stringWithFormat:@"RKManagedObjectStore_%p", self];
|
||||
if (! [threadDictionary valueForKey:objectStoreKey]) {
|
||||
[threadDictionary setObject:[NSMutableDictionary dictionary] forKey:objectStoreKey];
|
||||
@@ -232,7 +232,7 @@ static RKManagedObjectStore *defaultObjectStore = nil;
|
||||
*/
|
||||
- (BOOL)save:(NSError **)error
|
||||
{
|
||||
NSManagedObjectContext* moc = [self managedObjectContextForCurrentThread];
|
||||
NSManagedObjectContext *moc = [self managedObjectContextForCurrentThread];
|
||||
NSError *localError = nil;
|
||||
|
||||
@try {
|
||||
@@ -241,7 +241,7 @@ static RKManagedObjectStore *defaultObjectStore = nil;
|
||||
[self.delegate managedObjectStore:self didFailToSaveContext:moc error:localError exception:nil];
|
||||
}
|
||||
|
||||
NSDictionary* userInfo = [NSDictionary dictionaryWithObject:localError forKey:@"error"];
|
||||
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:localError forKey:@"error"];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:RKManagedObjectStoreDidFailSaveNotification object:self userInfo:userInfo];
|
||||
|
||||
if ([[localError domain] isEqualToString:@"NSCocoaErrorDomain"]) {
|
||||
@@ -281,7 +281,7 @@ static RKManagedObjectStore *defaultObjectStore = nil;
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
@catch (NSException* e) {
|
||||
@catch (NSException *e) {
|
||||
if (self.delegate != nil && [self.delegate respondsToSelector:@selector(managedObjectStore:didFailToSaveContext:error:exception:)]) {
|
||||
[self.delegate managedObjectStore:self didFailToSaveContext:moc error:nil exception:e];
|
||||
}
|
||||
@@ -304,14 +304,14 @@ static RKManagedObjectStore *defaultObjectStore = nil;
|
||||
return managedObjectContext;
|
||||
}
|
||||
|
||||
- (void)createStoreIfNecessaryUsingSeedDatabase:(NSString*)seedDatabase
|
||||
- (void)createStoreIfNecessaryUsingSeedDatabase:(NSString *)seedDatabase
|
||||
{
|
||||
if (NO == [[NSFileManager defaultManager] fileExistsAtPath:self.pathToStoreFile]) {
|
||||
NSString* seedDatabasePath = [[NSBundle mainBundle] pathForResource:seedDatabase ofType:nil];
|
||||
NSString *seedDatabasePath = [[NSBundle mainBundle] pathForResource:seedDatabase ofType:nil];
|
||||
NSAssert1(seedDatabasePath, @"Unable to find seed database file '%@' in the Main Bundle, aborting...", seedDatabase);
|
||||
RKLogInfo(@"No existing database found, copying from seed path '%@'", seedDatabasePath);
|
||||
|
||||
NSError* error;
|
||||
NSError *error;
|
||||
if (![[NSFileManager defaultManager] copyItemAtPath:seedDatabasePath toPath:self.pathToStoreFile error:&error]) {
|
||||
if (self.delegate != nil && [self.delegate respondsToSelector:@selector(managedObjectStore:didFailToCopySeedDatabase:error:)]) {
|
||||
[self.delegate managedObjectStore:self didFailToCopySeedDatabase:seedDatabase error:error];
|
||||
@@ -348,8 +348,8 @@ static RKManagedObjectStore *defaultObjectStore = nil;
|
||||
|
||||
- (void)deletePersistentStoreUsingSeedDatabaseName:(NSString *)seedFile
|
||||
{
|
||||
NSURL* storeURL = [NSURL fileURLWithPath:self.pathToStoreFile];
|
||||
NSError* error = nil;
|
||||
NSURL *storeURL = [NSURL fileURLWithPath:self.pathToStoreFile];
|
||||
NSError *error = nil;
|
||||
if ([[NSFileManager defaultManager] fileExistsAtPath:storeURL.path]) {
|
||||
if (![[NSFileManager defaultManager] removeItemAtPath:storeURL.path error:&error]) {
|
||||
if (self.delegate != nil && [self.delegate respondsToSelector:@selector(managedObjectStore:didFailToDeletePersistentStore:error:)]) {
|
||||
@@ -388,7 +388,7 @@ static RKManagedObjectStore *defaultObjectStore = nil;
|
||||
}
|
||||
|
||||
// Background threads leverage thread-local storage
|
||||
NSManagedObjectContext* managedObjectContext = [self threadLocalObjectForKey:RKManagedObjectStoreThreadDictionaryContextKey];
|
||||
NSManagedObjectContext *managedObjectContext = [self threadLocalObjectForKey:RKManagedObjectStoreThreadDictionaryContextKey];
|
||||
if (!managedObjectContext) {
|
||||
managedObjectContext = [self newManagedObjectContext];
|
||||
|
||||
@@ -406,7 +406,7 @@ static RKManagedObjectStore *defaultObjectStore = nil;
|
||||
return managedObjectContext;
|
||||
}
|
||||
|
||||
- (void)mergeChangesOnMainThreadWithNotification:(NSNotification*)notification
|
||||
- (void)mergeChangesOnMainThreadWithNotification:(NSNotification *)notification
|
||||
{
|
||||
assert([NSThread isMainThread]);
|
||||
[self.primaryManagedObjectContext performSelectorOnMainThread:@selector(mergeChangesFromContextDidSaveNotification:)
|
||||
@@ -423,19 +423,19 @@ static RKManagedObjectStore *defaultObjectStore = nil;
|
||||
#pragma mark -
|
||||
#pragma mark Helpers
|
||||
|
||||
- (NSManagedObject*)objectWithID:(NSManagedObjectID *)objectID
|
||||
- (NSManagedObject *)objectWithID:(NSManagedObjectID *)objectID
|
||||
{
|
||||
NSAssert(objectID, @"Cannot fetch a managedObject with a nil objectID");
|
||||
return [[self managedObjectContextForCurrentThread] objectWithID:objectID];
|
||||
}
|
||||
|
||||
- (NSArray*)objectsWithIDs:(NSArray*)objectIDs
|
||||
- (NSArray *)objectsWithIDs:(NSArray *)objectIDs
|
||||
{
|
||||
NSMutableArray* objects = [[NSMutableArray alloc] init];
|
||||
for (NSManagedObjectID* objectID in objectIDs) {
|
||||
NSMutableArray *objects = [[NSMutableArray alloc] init];
|
||||
for (NSManagedObjectID *objectID in objectIDs) {
|
||||
[objects addObject:[self objectWithID:objectID]];
|
||||
}
|
||||
NSArray* objectArray = [NSArray arrayWithArray:objects];
|
||||
NSArray *objectArray = [NSArray arrayWithArray:objects];
|
||||
[objects release];
|
||||
|
||||
return objectArray;
|
||||
|
||||
@@ -21,18 +21,18 @@
|
||||
#import "RKManagedObjectStore.h"
|
||||
|
||||
@interface RKManagedObjectThreadSafeInvocation : NSInvocation {
|
||||
NSMutableDictionary* _argumentKeyPaths;
|
||||
RKManagedObjectStore* _objectStore;
|
||||
NSMutableDictionary *_argumentKeyPaths;
|
||||
RKManagedObjectStore *_objectStore;
|
||||
}
|
||||
|
||||
@property (nonatomic, retain) RKManagedObjectStore* objectStore;
|
||||
@property (nonatomic, retain) RKManagedObjectStore *objectStore;
|
||||
|
||||
+ (RKManagedObjectThreadSafeInvocation*)invocationWithMethodSignature:(NSMethodSignature*)methodSignature;
|
||||
- (void)setManagedObjectKeyPaths:(NSSet*)keyPaths forArgument:(NSInteger)index;
|
||||
+ (RKManagedObjectThreadSafeInvocation *)invocationWithMethodSignature:(NSMethodSignature *)methodSignature;
|
||||
- (void)setManagedObjectKeyPaths:(NSSet *)keyPaths forArgument:(NSInteger)index;
|
||||
- (void)invokeOnMainThread;
|
||||
|
||||
// Private
|
||||
- (void)serializeManagedObjectsForArgument:(id)argument withKeyPaths:(NSSet*)keyPaths;
|
||||
- (void)deserializeManagedObjectIDsForArgument:(id)argument withKeyPaths:(NSSet*)keyPaths;
|
||||
- (void)serializeManagedObjectsForArgument:(id)argument withKeyPaths:(NSSet *)keyPaths;
|
||||
- (void)deserializeManagedObjectIDsForArgument:(id)argument withKeyPaths:(NSSet *)keyPaths;
|
||||
|
||||
@end
|
||||
|
||||
@@ -24,18 +24,18 @@
|
||||
|
||||
@synthesize objectStore = _objectStore;
|
||||
|
||||
+ (RKManagedObjectThreadSafeInvocation*)invocationWithMethodSignature:(NSMethodSignature*)methodSignature
|
||||
+ (RKManagedObjectThreadSafeInvocation *)invocationWithMethodSignature:(NSMethodSignature *)methodSignature
|
||||
{
|
||||
return (RKManagedObjectThreadSafeInvocation*) [super invocationWithMethodSignature:methodSignature];
|
||||
return (RKManagedObjectThreadSafeInvocation *) [super invocationWithMethodSignature:methodSignature];
|
||||
}
|
||||
|
||||
- (void)setManagedObjectKeyPaths:(NSSet*)keyPaths forArgument:(NSInteger)index
|
||||
- (void)setManagedObjectKeyPaths:(NSSet *)keyPaths forArgument:(NSInteger)index
|
||||
{
|
||||
if (nil == _argumentKeyPaths) {
|
||||
_argumentKeyPaths = [[NSMutableDictionary alloc] init];
|
||||
}
|
||||
|
||||
NSNumber* argumentIndex = [NSNumber numberWithInteger:index];
|
||||
NSNumber *argumentIndex = [NSNumber numberWithInteger:index];
|
||||
[_argumentKeyPaths setObject:keyPaths forKey:argumentIndex];
|
||||
}
|
||||
|
||||
@@ -52,18 +52,18 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)serializeManagedObjectsForArgument:(id)argument withKeyPaths:(NSSet*)keyPaths
|
||||
- (void)serializeManagedObjectsForArgument:(id)argument withKeyPaths:(NSSet *)keyPaths
|
||||
{
|
||||
for (NSString* keyPath in keyPaths) {
|
||||
for (NSString *keyPath in keyPaths) {
|
||||
id value = [argument valueForKeyPath:keyPath];
|
||||
if ([value isKindOfClass:[NSManagedObject class]]) {
|
||||
NSManagedObjectID *objectID = [(NSManagedObject*)value objectID];
|
||||
NSManagedObjectID *objectID = [(NSManagedObject *)value objectID];
|
||||
[self setValue:objectID forKeyPathOrKey:keyPath object:argument];
|
||||
} else if ([value respondsToSelector:@selector(allObjects)]) {
|
||||
id collection = [[[[[value class] alloc] init] autorelease] mutableCopy];
|
||||
for (id subObject in value) {
|
||||
if ([subObject isKindOfClass:[NSManagedObject class]]) {
|
||||
[collection addObject:[(NSManagedObject*)subObject objectID]];
|
||||
[collection addObject:[(NSManagedObject *)subObject objectID]];
|
||||
} else {
|
||||
[collection addObject:subObject];
|
||||
}
|
||||
@@ -75,13 +75,13 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)deserializeManagedObjectIDsForArgument:(id)argument withKeyPaths:(NSSet*)keyPaths
|
||||
- (void)deserializeManagedObjectIDsForArgument:(id)argument withKeyPaths:(NSSet *)keyPaths
|
||||
{
|
||||
for (NSString* keyPath in keyPaths) {
|
||||
for (NSString *keyPath in keyPaths) {
|
||||
id value = [argument valueForKeyPath:keyPath];
|
||||
if ([value isKindOfClass:[NSManagedObjectID class]]) {
|
||||
NSAssert(self.objectStore, @"Object store cannot be nil");
|
||||
NSManagedObject* managedObject = [self.objectStore objectWithID:(NSManagedObjectID*)value];
|
||||
NSManagedObject *managedObject = [self.objectStore objectWithID:(NSManagedObjectID *)value];
|
||||
NSAssert(managedObject, @"Expected managed object for ID %@, got nil", value);
|
||||
[self setValue:managedObject forKeyPathOrKey:keyPath object:argument];
|
||||
} else if ([value respondsToSelector:@selector(allObjects)]) {
|
||||
@@ -89,7 +89,7 @@
|
||||
for (id subObject in value) {
|
||||
if ([subObject isKindOfClass:[NSManagedObjectID class]]) {
|
||||
NSAssert(self.objectStore, @"Object store cannot be nil");
|
||||
NSManagedObject* managedObject = [self.objectStore objectWithID:(NSManagedObjectID*)subObject];
|
||||
NSManagedObject *managedObject = [self.objectStore objectWithID:(NSManagedObjectID *)subObject];
|
||||
[collection addObject:managedObject];
|
||||
} else {
|
||||
[collection addObject:subObject];
|
||||
@@ -103,8 +103,8 @@
|
||||
}
|
||||
- (void)serializeManagedObjects
|
||||
{
|
||||
for (NSNumber* argumentIndex in _argumentKeyPaths) {
|
||||
NSSet* managedKeyPaths = [_argumentKeyPaths objectForKey:argumentIndex];
|
||||
for (NSNumber *argumentIndex in _argumentKeyPaths) {
|
||||
NSSet *managedKeyPaths = [_argumentKeyPaths objectForKey:argumentIndex];
|
||||
id argument = nil;
|
||||
[self getArgument:&argument atIndex:[argumentIndex intValue]];
|
||||
if (argument) {
|
||||
@@ -115,8 +115,8 @@
|
||||
|
||||
- (void)deserializeManagedObjects
|
||||
{
|
||||
for (NSNumber* argumentIndex in _argumentKeyPaths) {
|
||||
NSSet* managedKeyPaths = [_argumentKeyPaths objectForKey:argumentIndex];
|
||||
for (NSNumber *argumentIndex in _argumentKeyPaths) {
|
||||
NSSet *managedKeyPaths = [_argumentKeyPaths objectForKey:argumentIndex];
|
||||
id argument = nil;
|
||||
[self getArgument:&argument atIndex:[argumentIndex intValue]];
|
||||
if (argument) {
|
||||
|
||||
@@ -22,11 +22,11 @@
|
||||
|
||||
@interface RKObjectPropertyInspector (CoreData)
|
||||
|
||||
- (NSDictionary *)propertyNamesAndTypesForEntity:(NSEntityDescription*)entity;
|
||||
- (NSDictionary *)propertyNamesAndTypesForEntity:(NSEntityDescription *)entity;
|
||||
|
||||
/**
|
||||
Returns the Class type of the specified property on the object class
|
||||
*/
|
||||
- (Class)typeForProperty:(NSString*)propertyName ofEntity:(NSEntityDescription*)entity;
|
||||
- (Class)typeForProperty:(NSString *)propertyName ofEntity:(NSEntityDescription *)entity;
|
||||
|
||||
@end
|
||||
|
||||
@@ -33,31 +33,31 @@ RK_FIX_CATEGORY_BUG(RKObjectPropertyInspector_CoreData)
|
||||
|
||||
@implementation RKObjectPropertyInspector (CoreData)
|
||||
|
||||
- (NSDictionary *)propertyNamesAndTypesForEntity:(NSEntityDescription*)entity
|
||||
- (NSDictionary *)propertyNamesAndTypesForEntity:(NSEntityDescription *)entity
|
||||
{
|
||||
NSMutableDictionary* propertyNamesAndTypes = [_cachedPropertyNamesAndTypes objectForKey:[entity name]];
|
||||
NSMutableDictionary *propertyNamesAndTypes = [_cachedPropertyNamesAndTypes objectForKey:[entity name]];
|
||||
if (propertyNamesAndTypes) {
|
||||
return propertyNamesAndTypes;
|
||||
}
|
||||
|
||||
propertyNamesAndTypes = [NSMutableDictionary dictionary];
|
||||
for (NSString* name in [entity attributesByName]) {
|
||||
NSAttributeDescription* attributeDescription = [[entity attributesByName] valueForKey:name];
|
||||
for (NSString *name in [entity attributesByName]) {
|
||||
NSAttributeDescription *attributeDescription = [[entity attributesByName] valueForKey:name];
|
||||
if ([attributeDescription attributeValueClassName]) {
|
||||
[propertyNamesAndTypes setValue:NSClassFromString([attributeDescription attributeValueClassName]) forKey:name];
|
||||
|
||||
} else if ([attributeDescription attributeType] == NSTransformableAttributeType &&
|
||||
![name isEqualToString:@"_mapkit_hasPanoramaID"]) {
|
||||
|
||||
const char* className = [[entity managedObjectClassName] cStringUsingEncoding:NSUTF8StringEncoding];
|
||||
const char* propertyName = [name cStringUsingEncoding:NSUTF8StringEncoding];
|
||||
const char *className = [[entity managedObjectClassName] cStringUsingEncoding:NSUTF8StringEncoding];
|
||||
const char *propertyName = [name cStringUsingEncoding:NSUTF8StringEncoding];
|
||||
Class managedObjectClass = objc_getClass(className);
|
||||
|
||||
// property_getAttributes() returns everything we need to implement this...
|
||||
// See: http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtPropertyIntrospection.html#//apple_ref/doc/uid/TP40008048-CH101-SW5
|
||||
objc_property_t prop = class_getProperty(managedObjectClass, propertyName);
|
||||
NSString* attributeString = [NSString stringWithCString:property_getAttributes(prop) encoding:NSUTF8StringEncoding];
|
||||
const char* destinationClassName = [[RKObjectPropertyInspector propertyTypeFromAttributeString:attributeString] cStringUsingEncoding:NSUTF8StringEncoding];
|
||||
NSString *attributeString = [NSString stringWithCString:property_getAttributes(prop) encoding:NSUTF8StringEncoding];
|
||||
const char *destinationClassName = [[RKObjectPropertyInspector propertyTypeFromAttributeString:attributeString] cStringUsingEncoding:NSUTF8StringEncoding];
|
||||
Class destinationClass = objc_getClass(destinationClassName);
|
||||
if (destinationClass) {
|
||||
[propertyNamesAndTypes setObject:destinationClass forKey:name];
|
||||
@@ -65,12 +65,12 @@ RK_FIX_CATEGORY_BUG(RKObjectPropertyInspector_CoreData)
|
||||
}
|
||||
}
|
||||
|
||||
for (NSString* name in [entity relationshipsByName]) {
|
||||
NSRelationshipDescription* relationshipDescription = [[entity relationshipsByName] valueForKey:name];
|
||||
for (NSString *name in [entity relationshipsByName]) {
|
||||
NSRelationshipDescription *relationshipDescription = [[entity relationshipsByName] valueForKey:name];
|
||||
if ([relationshipDescription isToMany]) {
|
||||
[propertyNamesAndTypes setValue:[NSSet class] forKey:name];
|
||||
} else {
|
||||
NSEntityDescription* destinationEntity = [relationshipDescription destinationEntity];
|
||||
NSEntityDescription *destinationEntity = [relationshipDescription destinationEntity];
|
||||
Class destinationClass = NSClassFromString([destinationEntity managedObjectClassName]);
|
||||
[propertyNamesAndTypes setValue:destinationClass forKey:name];
|
||||
}
|
||||
@@ -81,7 +81,7 @@ RK_FIX_CATEGORY_BUG(RKObjectPropertyInspector_CoreData)
|
||||
return propertyNamesAndTypes;
|
||||
}
|
||||
|
||||
- (Class)typeForProperty:(NSString*)propertyName ofEntity:(NSEntityDescription*)entity
|
||||
- (Class)typeForProperty:(NSString *)propertyName ofEntity:(NSEntityDescription *)entity
|
||||
{
|
||||
return [[self propertyNamesAndTypesForEntity:entity] valueForKey:propertyName];
|
||||
}
|
||||
|
||||
@@ -25,16 +25,16 @@ extern NSString * const RKSearchWordPrimaryKeyAttribute;
|
||||
|
||||
@interface RKSearchWord : NSManagedObject
|
||||
|
||||
@property (nonatomic, retain) NSString* word;
|
||||
@property (nonatomic, retain) NSSet* searchableManagedObjects;
|
||||
@property (nonatomic, retain) NSString *word;
|
||||
@property (nonatomic, retain) NSSet *searchableManagedObjects;
|
||||
|
||||
@end
|
||||
|
||||
@interface RKSearchWord (SearchableManagedObjectsAccessors)
|
||||
|
||||
- (void)addSearchableManagedObjectsObject:(RKSearchableManagedObject*)searchableManagedObject;
|
||||
- (void)removeSearchableManagedObjectsObject:(RKSearchableManagedObject*)searchableManagedObject;
|
||||
- (void)addSearchableManagedObjects:(NSSet*)searchableManagedObjects;
|
||||
- (void)removeSearchableManagedObjects:(NSSet*)searchableManagedObjects;
|
||||
- (void)addSearchableManagedObjectsObject:(RKSearchableManagedObject *)searchableManagedObject;
|
||||
- (void)removeSearchableManagedObjectsObject:(RKSearchableManagedObject *)searchableManagedObject;
|
||||
- (void)addSearchableManagedObjects:(NSSet *)searchableManagedObjects;
|
||||
- (void)removeSearchableManagedObjects:(NSSet *)searchableManagedObjects;
|
||||
|
||||
@end
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
|
||||
- (void)refreshSearchWords
|
||||
{
|
||||
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
RKLogDebug(@"Refreshing search words for %@ %@", NSStringFromClass([self class]), [self objectID]);
|
||||
NSMutableSet *searchWords = [NSMutableSet set];
|
||||
|
||||
Reference in New Issue
Block a user