iphone - Crash when using Between Predicate Statement and Float -
so i'm searching core data item inside current map's longitude , latitude. everytime run statement crashes.
the code:
nserror *error = nil; nsfetchrequest *boutiquerequest = [[nsfetchrequest alloc] init]; nspredicate *predicatetorun = nil; [boutiquerequest setentity:[nsentitydescription entityforname:@"boutique" inmanagedobjectcontext:managedobjectcontext]]; nslog(@"ne longitude: %f", [necoordlong floatvalue]); nslog(@"ne latitude: %f", [necoordlat floatvalue]); nslog(@"sw longitude: %f", [swcoordlong floatvalue]); nslog(@"sw latitude: %f", [swcoordlat floatvalue]); nspredicate *longpredicate = [nspredicate predicatewithformat: @"longitude between %@", [nsarray arraywithobjects:necoordlong, swcoordlong, nil]]; nspredicate *latpredicate = [nspredicate predicatewithformat: @"latitude between %@", [nsarray arraywithobjects:necoordlat, swcoordlat, nil]]; predicatetorun = [nscompoundpredicate andpredicatewithsubpredicates:[nsarray arraywithobjects:longpredicate, latpredicate, nil]]; [boutiquerequest setpredicate:predicatetorun]; nslog(@"%@", [boutiquerequest predicate]); nsarray *results = [managedobjectcontext executefetchrequest:boutiquerequest error:&error];
as call executefetchrequest gives me following crash report
2011-02-24 17:42:43.183 dl2[363:207] ne longitude: 153.5058 2011-02-24 17:42:43.183 dl2[363:207] ne latitude: -27.811142 2011-02-24 17:42:43.183 dl2[363:207] sw longitude: 153.286057 2011-02-24 17:42:43.184 dl2[363:207] sw latitude: -28.033804 2011-02-24 17:42:43.184 dl2[363:207] longitude between {153.5058, 153.2861} , latitude between {-27.81114, -28.0338}
2011-02-24 13:57:18.916 dl2[9628:207] -[nscfnumber constantvalue]: unrecognized selector sent instance 0x954ba80 2011-02-24 13:57:18.925 dl2[9628:207] *** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[nscfnumber constantvalue]: unrecognized selector sent instance 0x954ba80' *** call stack @ first throw: ( 0 corefoundation 0x0121abe9 __exceptionpreprocess + 185 1 libobjc.a.dylib 0x0136f5c2 objc_exception_throw + 47 2 corefoundation 0x0121c6fb -[nsobject(nsobject) doesnotrecognizeselector:] + 187 3 corefoundation 0x0118c366 ___forwarding___ + 966 4 corefoundation 0x0118bf22 _cf_forwarding_prep_0 + 50 5 coredata 0x00e18a0b -[nssqlsimplewhereintermediate _generatesqlbetweenstringincontext:] + 1211 6 coredata 0x00d48931 -[nssqlsimplewhereintermediate generatesqlstringincontext:] + 897 7 coredata 0x00d4843d -[nssqlcompoundwhereintermediate _generatemulticlausestringincontext:] + 205 8 coredata 0x00d48342 -[nssqlcompoundwhereintermediate generatesqlstringincontext:] + 770 9 coredata 0x00d47afa -[nssqlfetchintermediate generatesqlstringincontext:] + 122 10 coredata 0x00e0b31d -[nssqlgenerator newsqlstatementforfetchrequest:ignoreinheritance:countonly:nestinglevel:] + 413 11 coredata 0x00d43a78 -[nssqladapter _newselectstatementwithfetchrequest:ignoreinheritance:] + 488 12 coredata 0x00d43881 -[nssqladapter newselectstatementwithfetchrequest:] + 49 13 coredata 0x00d4372e -[nssqlcore newrowsforfetchplan:] + 430 14 coredata 0x00d42ab5 -[nssqlcore objectsforfetchrequest:incontext:] + 357 15 coredata 0x00d4266e -[nssqlcore executerequest:withcontext:error:] + 206 16 coredata 0x00df20ec -[nspersistentstorecoordinator executerequest:withcontext:error:] + 1084 17 coredata 0x00d3f807 -[nsmanagedobjectcontext executefetchrequest:error:] + 359 18 dl2 0x00021060 -[boutiquelistviewcontroller getboutiquestoshow] + 1449 19 dl2 0x0002164f -[boutiquelistviewcontroller viewdidload] + 211 20 uikit 0x003f265e -[uiviewcontroller view] + 179 21 dl2 0x0001ff4e -[boutiquemaptabviewcontroller openlist] + 698 22 dl2 0x0001f9f3 -[boutiquemaptabviewcontroller tabbar:didselectitem:] + 110 23 uikit 0x00542167 -[uitabbar _sendaction:withevent:] + 283 24 uikit 0x00344a6e -[uiapplication sendaction:to:from:forevent:] + 119 25 uikit 0x003d31b5 -[uicontrol sendaction:to:forevent:] + 67 26 uikit 0x003d5647 -[uicontrol(internal) _sendactionsforevents:withevent:] + 527 27 uikit 0x003d316c -[uicontrol sendactionsforcontrolevents:] + 49 28 uikit 0x00344a6e -[uiapplication sendaction:to:from:forevent:] + 119 29 uikit 0x003d31b5 -[uicontrol sendaction:to:forevent:] + 67 30 uikit 0x003d5647 -[uicontrol(internal) _sendactionsforevents:withevent:] + 527 31 uikit 0x003d41f4 -[uicontrol touchesended:withevent:] + 458 32 uikit 0x003690d1 -[uiwindow _sendtouchesforevent:] + 567 33 uikit 0x0034a37a -[uiapplication sendevent:] + 447 34 uikit 0x0034f732 _uiapplicationhandleevent + 7576 35 graphicsservices 0x01b3da36 purpleeventcallback + 1550 36 corefoundation 0x011fc064 __cfrunloop_is_calling_out_to_a_source1_perform_function__ + 52 37 corefoundation 0x0115c6f7 __cfrunloopdosource1 + 215 38 corefoundation 0x01159983 __cfrunlooprun + 979 39 corefoundation 0x01159240 cfrunlooprunspecific + 208 40 corefoundation 0x01159161 cfrunloopruninmode + 97 41 graphicsservices 0x01b3c268 gseventrunmodal + 217 42 graphicsservices 0x01b3c32d gseventrun + 115 43 uikit 0x0035342e uiapplicationmain + 1160 44 dl2 0x000028fc main + 102 45 dl2 0x0000288d start + 53
i can't seem see problem. don't know if i'm close it, or if it's being float or what! appreciated
well wasn't able solve why between function didn't work - mysql doesn't allow between on floating point numbers either. i'm going assume it's similar reason.
i changed code merely create it's own between statement.
nspredicate *longpredicate = nil; nspredicate *latpredicate = nil; if ([necoordlong floatvalue] > [swcoordlong floatvalue]) { longpredicate = [nspredicate predicatewithformat: @" longitude <= %@ , longitude >= %@", necoordlong, swcoordlong]; }else { longpredicate = [nspredicate predicatewithformat: @" longitude <= %@ , longitude >= %@", swcoordlong, necoordlong]; } if ([necoordlat floatvalue] > [swcoordlat floatvalue]) { latpredicate = [nspredicate predicatewithformat: @" latitude <= %@ , latitude >= %@", necoordlat, swcoordlat]; }else { latpredicate = [nspredicate predicatewithformat: @" latitude <= %@ , latitude >= %@", swcoordlat, necoordlat]; }
hopefully helps else
Comments
Post a Comment