Associating a relationship after getObjectsAtPath

7 views
Skip to first unread message

William Noto

unread,
Jun 30, 2015, 11:47:15 PM6/30/15
to res...@googlegroups.com
I want to cache search results in core data to provide fast performance and a really strong user experience.

My "Search" is defined as a core data object with location (latitude, longitude, within radius, and keyword) and my searchResult objects are associated to them through NSManagedObject relationships... I don't have (or want) foreign keys, per se, to associate the search to the search results. 

Is there any obvious reason why this would crash?

    - (void) fetchResultsForSearch:(HNEquipmentSearch*) search then:(void (^)(NSArray* results, NSError * error))completionHandler {

        if ([search.results count] > 0) {

            completionHandler([search.results array], nil);

        } else {

            NSMutableDictionary *queryParams = [NSMutableDictionary dictionaryWithDictionary:

                                                @{ @"within" : search.within,

                                                   @"lat" : search.latitude,

                                                   @"long" : search.longitude,

                                                   @"keyword" : (search.keyword ?: @"") }];

        

            [[RKObjectManager sharedManager] getObjectsAtPath:@"equipment" parameters:queryParams

             success: ^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {

                 //equipment has been saved in core data by now

                 for (HNEquipmentSearchResult *eqSR in mappingResult.array) {

                     //                 [eqSR setSearch:search]; // CRASHED

                     //                 [eqSR setValue:search forKey:@"search"]; // CRASHED

                     [search addResultsObject:eqSR]; // CRASHED

                 }

             

                 if (completionHandler)

                     completionHandler(mappingResult.array, nil);

            }

             failure: ^(RKObjectRequestOperation *operation, NSError *error) {

                 RKLogError(@"Load failed with error: %@", error);

                 if (completionHandler)

                     completionHandler(nil, error);

             }];

    }


Reply all
Reply to author
Forward
0 new messages