Associating a relationship after getObjectsAtPath

Skip to first unread message

William Noto

Jun 30, 2015, 11:47:15 PM6/30/15
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
0 new messages