Convert RestKit to ARC

This commit is contained in:
Blake Watters
2012-08-28 17:34:58 -04:00
parent 274478448d
commit ce6b0829e4
81 changed files with 2615 additions and 3128 deletions

View File

@@ -31,7 +31,6 @@ static char searchIndexerAssociationKey;
{
RKSearchIndexer *searchIndexer = [RKSearchIndexer new];
self.searchIndexer = searchIndexer;
[searchIndexer release];
}
- (void)addSearchIndexingToEntityForName:(NSString *)entityName onAttributes:(NSArray *)attributes

View File

@@ -51,7 +51,7 @@ extern NSString * const RKSearchableAttributeNamesUserInfoKey;
An optional set of stop words to be removed from the set of tokens
used to create the search words for indexed entities.
*/
@property (nonatomic, retain) NSSet *stopWords;
@property (nonatomic, strong) NSSet *stopWords;
///-----------------------------------------------------------------------------
/// @name Indexing Changes in a Managed Object Context

View File

@@ -28,7 +28,7 @@ NSString * const RKSearchableAttributeNamesUserInfoKey = @"RestKitSearchableAttr
// Create a relationship from the RKSearchWordEntity to the given searchable entity
NSEntityDescription *searchWordEntity = [[entity.managedObjectModel entitiesByName] objectForKey:RKSearchWordEntityName];
if (! searchWordEntity) {
searchWordEntity = [[[RKSearchWordEntity alloc] init] autorelease];
searchWordEntity = [[RKSearchWordEntity alloc] init];
// Add the entity to the model
NSArray *entities = [entity.managedObjectModel entities];
@@ -81,8 +81,6 @@ NSString * const RKSearchableAttributeNamesUserInfoKey = @"RestKitSearchableAttr
[relationship setInverseRelationship:inverseRelationship];
[inverseRelationship setInverseRelationship:relationship];
[inverseRelationship release];
[relationship release];
}
- (void)startObservingManagedObjectContext:(NSManagedObjectContext *)managedObjectContext
@@ -104,62 +102,62 @@ NSString * const RKSearchableAttributeNamesUserInfoKey = @"RestKitSearchableAttr
- (NSUInteger)indexManagedObject:(NSManagedObject *)managedObject
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
@autoreleasepool {
RKLogDebug(@"Indexing searchable attributes of managed object: %@", managedObject);
NSArray *searchableAttributes = [managedObject.entity.userInfo objectForKey:RKSearchableAttributeNamesUserInfoKey];
if (! searchableAttributes) {
[NSException raise:NSInvalidArgumentException format:@"The given managed object %@ is for an entity (%@) that does not define any searchable attributes. Perhaps you forgot to invoke addSearchIndexingToEntity:onAttributes:?", managedObject, managedObject.entity];
return NSNotFound;
}
RKSearchTokenizer *searchTokenizer = [RKSearchTokenizer new];
searchTokenizer.stopWords = self.stopWords;
__block NSUInteger searchWordCount;
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:RKSearchWordEntityName];
fetchRequest.fetchLimit = 1;
NSPredicate *predicateTemplate = [NSPredicate predicateWithFormat:@"%K == $SEARCH_WORD", RKSearchWordAttributeName];
NSManagedObjectContext *managedObjectContext = managedObject.managedObjectContext;
[managedObjectContext performBlockAndWait:^{
NSMutableSet *searchWords = [NSMutableSet set];
for (NSString *searchableAttribute in searchableAttributes) {
NSString *attributeValue = [managedObject valueForKey:searchableAttribute];
if (attributeValue) {
RKLogTrace(@"Generating search words for searchable attribute: %@", searchableAttribute);
NSSet *tokens = [searchTokenizer tokenize:attributeValue];
for (NSString *word in tokens) {
if (word && [word length] > 0) {
fetchRequest.predicate = [predicateTemplate predicateWithSubstitutionVariables:@{ @"SEARCH_WORD" : word }];
NSError *error = nil;
NSArray *results = [managedObject.managedObjectContext executeFetchRequest:fetchRequest error:&error];
if (results) {
RKSearchWord *searchWord;
if ([results count] == 0) {
searchWord = [NSEntityDescription insertNewObjectForEntityForName:RKSearchWordEntityName inManagedObjectContext:managedObjectContext];
searchWord.word = word;
RKLogDebug(@"Indexing searchable attributes of managed object: %@", managedObject);
NSArray *searchableAttributes = [managedObject.entity.userInfo objectForKey:RKSearchableAttributeNamesUserInfoKey];
if (! searchableAttributes) {
[NSException raise:NSInvalidArgumentException format:@"The given managed object %@ is for an entity (%@) that does not define any searchable attributes. Perhaps you forgot to invoke addSearchIndexingToEntity:onAttributes:?", managedObject, managedObject.entity];
return NSNotFound;
}
RKSearchTokenizer *searchTokenizer = [RKSearchTokenizer new];
searchTokenizer.stopWords = self.stopWords;
__block NSUInteger searchWordCount;
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:RKSearchWordEntityName];
fetchRequest.fetchLimit = 1;
NSPredicate *predicateTemplate = [NSPredicate predicateWithFormat:@"%K == $SEARCH_WORD", RKSearchWordAttributeName];
NSManagedObjectContext *managedObjectContext = managedObject.managedObjectContext;
[managedObjectContext performBlockAndWait:^{
NSMutableSet *searchWords = [NSMutableSet set];
for (NSString *searchableAttribute in searchableAttributes) {
NSString *attributeValue = [managedObject valueForKey:searchableAttribute];
if (attributeValue) {
RKLogTrace(@"Generating search words for searchable attribute: %@", searchableAttribute);
NSSet *tokens = [searchTokenizer tokenize:attributeValue];
for (NSString *word in tokens) {
if (word && [word length] > 0) {
fetchRequest.predicate = [predicateTemplate predicateWithSubstitutionVariables:@{ @"SEARCH_WORD" : word }];
NSError *error = nil;
NSArray *results = [managedObject.managedObjectContext executeFetchRequest:fetchRequest error:&error];
if (results) {
RKSearchWord *searchWord;
if ([results count] == 0) {
searchWord = [NSEntityDescription insertNewObjectForEntityForName:RKSearchWordEntityName inManagedObjectContext:managedObjectContext];
searchWord.word = word;
} else {
searchWord = [results objectAtIndex:0];
}
[searchWords addObject:searchWord];
} else {
searchWord = [results objectAtIndex:0];
RKLogError(@"Failed to retrieve search word: %@", error);
}
[searchWords addObject:searchWord];
} else {
RKLogError(@"Failed to retrieve search word: %@", error);
}
}
}
}
}
[managedObject setValue:searchWords forKey:RKSearchWordsRelationshipName];
RKLogTrace(@"Indexed search words: %@", [searchWords valueForKey:RKSearchWordAttributeName]);
searchWordCount = [searchWords count];
}];
[managedObject setValue:searchWords forKey:RKSearchWordsRelationshipName];
RKLogTrace(@"Indexed search words: %@", [searchWords valueForKey:RKSearchWordAttributeName]);
searchWordCount = [searchWords count];
}];
[pool drain];
return searchWordCount;
return searchWordCount;
}
}
- (void)indexChangedObjectsInManagedObjectContext:(NSManagedObjectContext *)managedObjectContext

View File

@@ -13,14 +13,13 @@
+ (NSPredicate *)searchPredicateWithText:(NSString *)searchText type:(NSCompoundPredicateType)type
{
return [[[self alloc] initWithSearchText:searchText type:type] autorelease];
return [[self alloc] initWithSearchText:searchText type:type];
}
- (id)initWithSearchText:(NSString *)searchText type:(NSCompoundPredicateType)type
{
RKSearchTokenizer *tokenizer = [RKSearchTokenizer new];
NSSet *searchWords = [tokenizer tokenize:searchText];
[tokenizer release];
NSMutableArray *subpredicates = [NSMutableArray arrayWithCapacity:[searchWords count]];
for (NSString *searchWord in searchWords) {

View File

@@ -25,7 +25,7 @@
Defaults to nil.
*/
@property (nonatomic, retain) NSSet *stopWords;
@property (nonatomic, strong) NSSet *stopWords;
///-----------------------------------------------------------------------------
/// @name Tokenizing a String of Text

View File

@@ -32,6 +32,6 @@
/**
A single search word extracted from an indexed entity.
*/
@property (nonatomic, retain) NSString *word;
@property (nonatomic, strong) NSString *word;
@end