Earlier I was sorting NSMutableArray in below way.
NSSortDescriptor *sortDescriptor1;
sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:#"Carton_IsDelivered"
ascending:NO];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor1];
customerDetailsArray = [[customerDetailsArray sortedArrayUsingDescriptors:sortDescriptors] mutableCopy];
This was sorting based on Carton_IsDelivered value which hold true & false value.
This was working fine.
Now as per new requirement, I want to sort by Carton_IsDelivered & Carton_AreaName.
What I want is
Carton_IsDelivered=true group by Carton_AreaName
+Carton_IsDelivered=false group by Carton_AreaName
For that I used below.
NSSortDescriptor *sortDescriptor1;
NSSortDescriptor *sortDescriptor2;
sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:#"Carton_IsDelivered"
ascending:NO];
sortDescriptor2 = [[NSSortDescriptor alloc] initWithKey:#"Carton_AreaName"
ascending:NO];
NSArray *sortDescriptors = [NSArray arrayWithObject:#[sortDescriptor1, sortDescriptor2]];
customerDetailsArray = [[customerDetailsArray sortedArrayUsingDescriptors:sortDescriptors] mutableCopy];
However the app crash saying below.
2015-03-30 11:35:45.402 Delivery[74822:9478073] -[__NSArrayI ascending]: unrecognized selector sent to instance 0x7ca5a660
2015-03-30 11:35:45.433 Delivery[74822:9478073] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI ascending]: unrecognized selector sent to instance 0x7ca5a660'
*** First throw call stack:
(
0 CoreFoundation 0x01f6f466 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x01bf8a97 objc_exception_throw + 44
2 CoreFoundation 0x01f772c5 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277
3 CoreFoundation 0x01ebfbc7 ___forwarding___ + 1047
4 CoreFoundation 0x01ebf78e _CF_forwarding_prep_0 + 14
5 Foundation 0x017d611e _NSInitializeCacheLine + 60
6 Foundation 0x017d5ee0 _sortedObjectsUsingDescriptors + 293
7 Foundation 0x017d5d51 -[NSArray(NSKeyValueSorting) sortedArrayUsingDescriptors:] + 713
8 Delivery 0x000d4388 -[DeliveryViewController bringDeliveredToTop] + 392
9 Delivery 0x000d0b4b -[DeliveryViewController parserDidEndDocument:] + 875
10 Foundation 0x018b1c34 _endDocument + 89
11 libxml2.2.dylib 0x057b6150 xmlParseChunk + 1366
12 Foundation 0x018afbf4 -[NSXMLParser finishIncrementalParse] + 58
13 Foundation 0x018afd95 -[NSXMLParser parseFromStream] + 385
14 Foundation 0x018afea8 -[NSXMLParser parse] + 33
15 Delivery 0x000cdfdc -[DeliveryViewController connectionDidFinishLoading:] + 1836
16 CFNetwork 0x05a1df39 ___ZL32_NSURLConnectionDidFinishLoadingP16_CFURLConnectionPKv_block_invoke + 40
17 CFNetwork 0x05a35af9 __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke + 83
18 CFNetwork 0x05a1cfe9 -[NSURLConnectionInternalConnection invokeForDelegate:] + 145
19 CFNetwork 0x05a35a93 -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 189
20 CFNetwork 0x05a35c46 -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 58
21 CFNetwork 0x05a1c5e0 _ZL32_NSURLConnectionDidFinishLoadingP16_CFURLConnectionPKv + 43
22 CFNetwork 0x058e5fc5 ___ZN27URLConnectionClient_Classic26_delegate_didFinishLoadingEU13block_pointerFvvE_block_invoke + 115
23 CFNetwork 0x059c59ad ___ZN27URLConnectionClient_Classic18_withDelegateAsyncEPKcU13block_pointerFvP16_CFURLConnectionPK33CFURLConnectionClientCurrent_VMaxE_block_invoke_2 + 290
24 CFNetwork 0x058d064c _ZN19RunloopBlockContext13_invoke_blockEPKvPv + 70
25 CoreFoundation 0x01e63db9 CFArrayApplyFunction + 57
26 CFNetwork 0x058d050d _ZN19RunloopBlockContext7performEv + 149
27 CFNetwork 0x05a26fd6 _ZThn16_N19RunloopBlockContext24multiplexerClientPerformEv + 20
28 CFNetwork 0x058d0350 _ZN17MultiplexerSource7performEv + 292
29 CFNetwork 0x058d016c _ZN17MultiplexerSource8_performEPv + 76
30 CoreFoundation 0x01e9298f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
31 CoreFoundation 0x01e8849d __CFRunLoopDoSources0 + 253
32 CoreFoundation 0x01e879f8 __CFRunLoopRun + 952
33 CoreFoundation 0x01e8737b CFRunLoopRunSpecific + 443
34 CoreFoundation 0x01e871ab CFRunLoopRunInMode + 123
35 GraphicsServices 0x0424d2c1 GSEventRunModal + 192
36 GraphicsServices 0x0424d0fe GSEventRun + 104
37 UIKit 0x005be9b6 UIApplicationMain + 1526
38 Delivery 0x000b4882 main + 130
39 libdyld.dylib 0x04772ac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Any idea what I am doing wrong?
As far as I see you use arrayWithObject which takes only one parameter, and you pass array so you have array which contains another array, you need to have just one array with two objects, try this instead:
NSArray *sortDescriptors = [NSArray arrayWithObjects:sortDescriptor1, sortDescriptor2, nil];
Change the arrayWithObject: to arrayWithObjects:
NSArray *sortDescriptors = [NSArray arrayWithObjects:#[sortDescriptor1, sortDescriptor2]];
Related
I am using for in loop to fetch data from plist. But it is showing following exception:
2015-07-16 11:16:43.597 plistNeha[640:60b] -[__NSCFDictionary objectAtIndexedSubscript:]: unrecognized selector sent to instance 0x8d671b0
2015-07-16 11:16:43.721 plistNeha[640:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary objectAtIndexedSubscript:]: unrecognized selector sent to instance 0x8d671b0'
*** First throw call stack:
(
0 CoreFoundation 0x017ed1e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x0156c8e5 objc_exception_throw + 44
2 CoreFoundation 0x0188a243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x017dd50b ___forwarding___ + 1019
4 CoreFoundation 0x017dd0ee _CF_forwarding_prep_0 + 14
5 plistNeha 0x00002b7d -[sdViewController plistbtn:] + 333
6 libobjc.A.dylib 0x0157e880 -[NSObject performSelector:withObject:withObject:] + 77
7 UIKit 0x0022e3b9 -[UIApplication sendAction:to:from:forEvent:] + 108
8 UIKit 0x0022e345 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
9 UIKit 0x0032fbd1 -[UIControl sendAction:to:forEvent:] + 66
10 UIKit 0x0032ffc6 -[UIControl _sendActionsForEvents:withEvent:] + 577
11 UIKit 0x0032f243 -[UIControl touchesEnded:withEvent:] + 641
12 UIKit 0x0026dddd -[UIWindow _sendTouchesForEvent:] + 852
13 UIKit 0x0026e9d1 -[UIWindow sendEvent:] + 1117
14 UIKit 0x002405f2 -[UIApplication sendEvent:] + 242
15 UIKit 0x0022a353 _UIApplicationHandleEventQueue + 11455
16 CoreFoundation 0x0177677f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
17 CoreFoundation 0x0177610b __CFRunLoopDoSources0 + 235
18 CoreFoundation 0x017931ae __CFRunLoopRun + 910
19 CoreFoundation 0x017929d3 CFRunLoopRunSpecific + 467
20 CoreFoundation 0x017927eb CFRunLoopRunInMode + 123
21 GraphicsServices 0x037e15ee GSEventRunModal + 192
22 GraphicsServices 0x037e142b GSEventRun + 104
23 UIKit 0x0022cf9b UIApplicationMain + 1225
24 plistNeha 0x00002e1d main + 141
25 libdyld.dylib 0x01e34701 start + 1
26 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Code:
NSString *path=[[NSBundle mainBundle]pathForResource:#"x" ofType:#"plist"];
ald=[[NSDictionary alloc]initWithContentsOfFile:path];
for(NSDictionary *awq in ald){
NSLog(#"check");
NSString *qqw=#"";
qqw=[awq objectForKey:#"qq"];
NSLog(#"%#",qqw);
}
But, if I am fetching data one by one then it is showing on debugger area. for in loop is also working as it is printing check. May be the line after NSLog(#"check"); is creating some exceptions.
Try this
NSString *path=[[NSBundle mainBundle]pathForResource:#"x" ofType:#"plist"];
NSDictionary *ald=[[NSDictionary alloc]initWithContentsOfFile:path];
for(NSDictionary *awq in [ald allValues]){
NSLog(#"check");
NSString *qqw=#"";
qqw=[awq objectForKey:#"qq"];
NSLog(#"%#",qqw);
}
for in on a dictionary is enumerating its keys, not values. See this question for each loop in objective c for accessing NSMutable dictionary
Try this:
NSString *path=[[NSBundle mainBundle]pathForResource:#"x" ofType:#"plist"];
NSDictionary *plistDictionary = [[NSDictionary alloc]initWithContentsOfFile:path];
for(NSString *key in plistDictionary){
NSDictionary *dictionary = [plistDictionary objectForKey:key];
NSLog(#"%#",[dictionary objectForKey:#"qq"]);
}
I had to change your variable names because it was too confusing to work with 'ald', 'awq', 'qqw' , etc.
I really get tired of trying to fix this so I think I need some help. I am filling each Cells of my iOS from an API which I successfully parsed (Can retrieve simple things such as texts, or numbers with no problem)
But when I tried to set the images for the thumbnails I am having some errors.
This is my code:
NSString *imageUrl = [tempDictionary valueForKeyPath:#"files.url_thumb"];
NSURL *url = [NSURL URLWithString:imageUrl];
NSData *imageData = [NSData dataWithContentsOfURL:url];
UIImage *thumbNailImage = [UIImage imageWithData:imageData];
dispatch_async(dispatch_get_main_queue(), ^{
[cell.ThumbImage setImage:thumbNailImage];
});
and this are the nightmares in my console:
2015-04-08 13:14:26.450 WebTableView[4976:173380] -[__NSArrayI length]:
unrecognized selector sent to instance 0x79e18b90
2015-04-08 13:14:26.509 WebTableView[4976:173380] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI length]: unrecognized selector sent to instance 0x79e18b90'
*** First throw call stack:
(
0 CoreFoundation 0x036c9466 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x03352a97 objc_exception_throw + 44
2 CoreFoundation 0x036d12c5 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277
3 CoreFoundation 0x03619bc7 ___forwarding___ + 1047
4 CoreFoundation 0x0361978e _CF_forwarding_prep_0 + 14
5 CoreFoundation 0x035836cf CFStringGetLength + 143
6 CoreFoundation 0x036a9c8d _CFURLCreateWithURLString + 77
7 CoreFoundation 0x035952d3 CFURLCreateWithString + 35
8 Foundation 0x02f17999 -[NSURL(NSURL) initWithString:relativeToURL:] + 371
9 Foundation 0x02f17807 +[NSURL(NSURL) URLWithString:relativeToURL:] + 80
10 Foundation 0x02f177b1 +[NSURL(NSURL) URLWithString:] + 48
11 WebTableView 0x00111a8b -[TableViewController tableView:cellForRowAtIndexPath:] + 571
12 UIKit 0x01c26c9c -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 473
13 UIKit 0x01c26d7e -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 77
14 UIKit 0x01c0054b -[UITableView _updateVisibleCellsNow:isRecursive:] + 3034
15 UIKit 0x01c1aeb1 -[UITableView layoutSubviews] + 222
16 UIKit 0x01b907b1 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 608
17 libobjc.A.dylib 0x03368771 -[NSObject performSelector:withObject:] + 70
18 QuartzCore 0x009421cf -[CALayer layoutSublayers] + 152
19 QuartzCore 0x00936055 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 397
20 QuartzCore 0x00935eb0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
21 QuartzCore 0x008941b6 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 284
22 QuartzCore 0x0089558a _ZN2CA11Transaction6commitEv + 392
23 QuartzCore 0x00895c56 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
24 CoreFoundation 0x035ec18e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
25 CoreFoundation 0x035ec0d0 __CFRunLoopDoObservers + 400
26 CoreFoundation 0x035e1b0a __CFRunLoopRun + 1226
27 CoreFoundation 0x035e137b CFRunLoopRunSpecific + 443
28 CoreFoundation 0x035e11ab CFRunLoopRunInMode + 123
29 GraphicsServices 0x04b3d2c1 GSEventRunModal + 192
30 GraphicsServices 0x04b3d0fe GSEventRun + 104
31 UIKit 0x01b049b6 UIApplicationMain + 1526
32 WebTableView 0x000dd6cd main + 141
33 libdyld.dylib 0x03e94ac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I think valueForKeyPath: returning an array of objects. Try logging imageUrl and check what you are getting.
If you are confident that there would be only one url then you can try this -
NSString *imageUrl = [[tempDictionary valueForKeyPath:#"files.url_thumb"] lastObject];
Else try something like this -
valueForKey:#"files"] valueForKey:#"url_thumb]
I am getting this crash showing up in BugSense:
-[NSConcreteData count]: unrecognized selector sent to instance 0x14e57f10 - NSInvalidArgumentException
in this code:
+ (NSMutableArray *)applyFilters:(NSMutableArray *)theItems fromFilter:(NSDictionary *)filters
{
NSMutableArray *items = [[NSMutableArray alloc] initWithArray:theItems];
if ([[filters allKeys] count] > 0)
{
NSMutableArray *tempFilteredItems = [[NSMutableArray alloc] init];
for (NSString *key in [filters allKeys])
{
NSMutableString *convertedKey = [NSMutableString stringWithString:key];
[convertedKey replaceOccurrencesOfString:#" "
withString:#"_"
options:NSCaseInsensitiveSearch
range:NSMakeRange(0, [convertedKey length])];
NSArray *tempFilterAttributes = [NSArray arrayWithArray:filters[key]];
for (NSDictionary *item in items)
{
if (![[item[convertedKey] componentsSeparatedByString:#"*"] firstObjectCommonWithArray:tempFilterAttributes])
{
if (![tempFilteredItems containsObject:item])
{
[tempFilteredItems addObject:item];
}
}
}
[items removeObjectsInArray:tempFilteredItems];
[tempFilteredItems removeAllObjects];
}
}
return items;
}
Why/how is this happening?
Stack trace is:
CoreFoundation <redacted> + 130
1 libobjc.A.dylib objc_exception_throw + 38
2 CoreFoundation <redacted> + 202
3 CoreFoundation <redacted> + 706
4 CoreFoundation _CF_forwarding_prep_0 + 24
5 CoreFoundation <redacted> + 28
6 Video Games +[Helper applyFilters:fromFilter:] (Helper.m:2862)
7 Video Games -[WishlistViewController loadUp] (WishlistViewController.m:409) + 29303
8 Video Games -[WishlistViewController viewWillAppear:] (WishlistViewController.m:363) + 27955
9 UIKit <redacted> + 374
10 UIKit <redacted> + 612
11 UIKit <redacted> + 572
12 UIKit <redacted> + 44
13 UIKit <redacted> + 184
14 UIKit <redacted> + 380
15 QuartzCore <redacted> + 142
16 QuartzCore <redacted> + 350
17 QuartzCore <redacted> + 16
18 QuartzCore <redacted> + 228
19 QuartzCore <redacted> + 314
20 UIKit <redacted> + 126
21 CoreFoundation <redacted> + 20
22 CoreFoundation <redacted> + 286
23 CoreFoundation <redacted> + 738
24 CoreFoundation CFRunLoopRunSpecific + 524
25 CoreFoundation CFRunLoopRunInMode + 106
26 GraphicsServices GSEventRunModal + 138
27 UIKit UIApplicationMain + 1136
28 Video Games main (main.m:16) + 888911
29 libdyld.dylib <redacted> + 2
The problem has nothing to do with the code that you provided. The error messages says that the message count was sent to the class NSConcreteData, which is essentially the same as NSData, and such a class method does not exist.
I suggest that you set an exception breakpoint (in Xcode select left the breakpoint navigator, click + left bottom, and select add exception breakpoint).
When you execute the app, it will stop at the faulty instruction.
EDIT (due to the stack trace you provided now):
The stack trace indeed says that your method applyFilters:fromFilter: is responsible for the crash. The only place where the message count is sent in this method, is the statement [[filters allKeys] count]. It looks then that count is sent to an NSConcreteData object, and not to an NSArray object as you might have expected. One reason could be that the argument filters, that should be a NSDictionary, is an object of a different type.
So when the app stops at the exception breakpoint, please check the class of the instance filters.
I have created an app that is running great on 5.0 and above but when I test on devices lower I have ran into a few issues that I am unsure of how to tackle and correct.
The first big issue is when saving to core data I use a error method that I believe is apples default error method that is created when you make a core data model. The app just crashes when below 5.0 but if I block out the error code everything works fine. Below is the code used to find and error and handle it.
NSError *error;
if (![managedObjectContext save:&error]) { // crash here
// This is a serious error saying the record could not be saved.
// Advise the user to restart the application
}
//crash log below
2012-05-13 10:17:22.062 PreviewMaker[41595:207] -[UIImage encodeWithCoder:]:
unrecognized selector sent to instance 0x5e7ce80
2012-05-13 10:17:22.064 PreviewMaker[41595:207] *** Terminating app due to uncaught
exception 'NSInvalidArgumentException', reason: '-[UIImage encodeWithCoder:]:
unrecognized selector sent to instance 0x5e7ce80'
*** Call stack at first throw:
(
0 CoreFoundation 0x013fc5a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0178b313 objc_exception_throw + 44
2 CoreFoundation 0x013fe0bb -[NSObject(NSObject)
doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x0136d966 ___forwarding___ + 966
4 CoreFoundation 0x0136d522 _CF_forwarding_prep_0 + 50
5 Foundation 0x00c45b3e _encodeObject + 1076
6 Foundation 0x00c50f89 +[NSKeyedArchiver
archivedDataWithRootObject:] + 206
7 CoreData 0x01122cb5 -[NSSQLiteConnection execute] +
2677
8 CoreData 0x011771d6 -[NSSQLiteConnection insertRow:]
+ 262
9 CoreData 0x01173e64 -[NSSQLConnection
performAdapterOperations:] + 180
10 CoreData 0x01173b0e -[NSSQLCore
_performChangesWithAdapterOps:] + 494
11 CoreData 0x011725ea -[NSSQLCore performChanges] + 410
12 CoreData 0x0116c038 -[NSSQLCore saveChanges:] + 216
13 CoreData 0x0112a199 -[NSSQLCore
executeRequest:withContext:error:] + 409
14 CoreData 0x011da70b -[NSPersistentStoreCoordinator
executeRequest:withContext:error:] + 3691
15 CoreData 0x01162948 -[NSManagedObjectContext save:] +
712
16 PreviewMaker 0x0000a0c0 -[MainViewController
noUploadJustSaveImage:] + 331
17 PreviewMaker 0x00009d3c -[MainViewController
UserConfirmedToSaveImage] + 756
18 UIKit 0x004774fd -[UIApplication
sendAction:to:from:forEvent:] + 119
19 UIKit 0x00507799 -[UIControl
sendAction:to:forEvent:] + 67
20 UIKit 0x00509c2b -[UIControl(Internal)
_sendActionsForEvents:withEvent:] + 527
21 UIKit 0x005087d8 -[UIControl
touchesEnded:withEvent:] + 458
22 UIKit 0x0049bded -[UIWindow _sendTouchesForEvent:]
+ 567
23 UIKit 0x0047cc37 -[UIApplication sendEvent:] + 447
24 UIKit 0x00481f2e _UIApplicationHandleEvent + 7576
25 GraphicsServices 0x01eb8992 PurpleEventCallback + 1550
26 CoreFoundation 0x013dd944
__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
27 CoreFoundation 0x0133dcf7 __CFRunLoopDoSource1 + 215
28 CoreFoundation 0x0133af83 __CFRunLoopRun + 979
29 CoreFoundation 0x0133a840 CFRunLoopRunSpecific + 208
30 CoreFoundation 0x0133a761 CFRunLoopRunInMode + 97
31 GraphicsServices 0x01eb71c4 GSEventRunModal + 217
32 GraphicsServices 0x01eb7289 GSEventRun + 115
33 UIKit 0x00485c93 UIApplicationMain + 1160
34 PreviewMaker 0x00002e07 main + 121
35 PreviewMaker 0x00002d85 start + 53
)
terminate called after throwing an instance of 'NSException'
Another issue I am running into is setting tintColor on UI objects such as the UISwitch. I have a settings controller that has several UISwitches and such which just about all have a tint color set on, but once agin anything below 5.0 crashes. How can I handle the two and not have to re-write the code just to be compatible with devices below 5.0.
shineSwitch = [[[UISwitch alloc] initWithFrame:CGRectZero] autorelease];
[cell.contentView addSubview:shineSwitch];
cell.accessoryView = shineSwitch;
[shineSwitch addTarget:self action:#selector(switchChanged:)
forControlEvents:UIControlEventValueChanged];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
shineSwitch.onTintColor = [UIColor colorWithRed:0.0 green:0.61 blue:0.99 alpha:1.0];
//crash Log below
2012-05-13 10:19:45.033 PreviewMaker[41611:207] -[UISwitch setOnTintColor:]:
unrecognized selector sent to instance 0x5eab860
2012-05-13 10:19:45.034 PreviewMaker[41611:207] *** Terminating app due to uncaught
exception 'NSInvalidArgumentException', reason: '-[UISwitch setOnTintColor:]:
unrecognized selector sent to instance 0x5eab860'
*** Call stack at first throw:
(
0 CoreFoundation 0x013fc5a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0178b313 objc_exception_throw + 44
2 CoreFoundation 0x013fe0bb -[NSObject(NSObject)
doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x0136d966 ___forwarding___ + 966
4 CoreFoundation 0x0136d522 _CF_forwarding_prep_0 + 50
5 PreviewMaker 0x0000f6fb -[FlipsideViewController
tableView:cellForRowAtIndexPath:] + 1353
6 UIKit 0x004ecb98 -
[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 634
7 UIKit 0x004e24cc -
[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] + 75
8 UIKit 0x004f78cc -
[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1561
9 UIKit 0x004ef90c -[UITableView layoutSubviews] +
242
10 QuartzCore 0x001e2a5a -[CALayer layoutSublayers] + 181
11 QuartzCore 0x001e4ddc CALayerLayoutIfNeeded + 220
12 QuartzCore 0x0018a0b4
_ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
13 QuartzCore 0x0018b294 _ZN2CA11Transaction6commitEv +
292
14 QuartzCore 0x0018b46d
_ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99
15 CoreFoundation 0x013dd89b
__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
16 CoreFoundation 0x013726e7 __CFRunLoopDoObservers + 295
17 CoreFoundation 0x0133b1d7 __CFRunLoopRun + 1575
18 CoreFoundation 0x0133a840 CFRunLoopRunSpecific + 208
19 CoreFoundation 0x0133a761 CFRunLoopRunInMode + 97
20 GraphicsServices 0x01eb71c4 GSEventRunModal + 217
21 GraphicsServices 0x01eb7289 GSEventRun + 115
22 UIKit 0x00485c93 UIApplicationMain + 1160
23 PreviewMaker 0x00002e07 main + 121
24 PreviewMaker 0x00002d85 start + 53
)
terminate called after throwing an instance of 'NSException'
Any help would be greatly appreciated!
I am seeing a really strange behavior in core data. I am doing a search for locations in core data (data store type is SQLite). The query is to look for location objects within a specific area. I am implementing the search as a between predicate.
NSExpression *lhs = [NSExpression expressionForKeyPath:keyPath];
NSExpression *rhs = [NSExpression expressionForVariable:#"MIN_MAX"];
NSPredicate *predicateTemplate =
[NSComparisonPredicate predicateWithLeftExpression:lhs
rightExpression:rhs
modifier:NSDirectPredicateModifier
type:NSBetweenPredicateOperatorType
options:0];
NSPredicate *predicate = [predicateTemplate predicateWithSubstitutionVariables:
[NSDictionary dictionaryWithObject:expressionArray forKey:#"MIN_MAX"]];
where expressions array is an array of 2 object, min in index 0, and max in index 1. Each object in the array is an NSConstantValueExpression, defined as :
NSExpression *ex = [NSExpression expressionForConstantValue : numberValue]
I am using the predicate in a NSFetchedResultsController, and the first time though works exactly as I expect. The final predicate is something like this:
NSFetchRequest: 0x7394360 (entity: Location; predicate: (longitude
BETWEEN {-122.0767937067412,
-121.7137663065599} AND latitude BETWEEN {37.16973380897733,
37.45968675392614} ); sortDescriptors: (("(name, ascending, compare:)"));
limit: 20; type:
NSManagedObjectResultType; )
And I get the results I want.
The second time this code is run (by pushing a second view on top, and closing that view. This causes the view to reload). The system crashes, with this error message.
-[NSConstantValueExpression compare:]: unrecognized selector sent
to instance 0x71bbea0
2011-04-22 10:54:11.742 Wines[13667:207] Terminating app
due to uncaught exception
'NSInvalidArgumentException', reason:
'-[NSConstantValueExpression
compare:]: unrecognized selector sent
to instance 0x71bbea0'*
Any suggestions?
Full stack below.
Thanks,
*** Call stack at first throw:
(
0 CoreFoundation 0x02f0bb99 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0305b40e objc_exception_throw + 47
2 CoreFoundation 0x02f0d6ab -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x02e7d2b6 ___forwarding___ + 966
4 CoreFoundation 0x02e7ce72 _CF_forwarding_prep_0 + 50
5 Foundation 0x002dd909 -[NSBetweenPredicateOperator performPrimitiveOperationUsingObject:andObject:] + 317
6 Foundation 0x0020aee4 -[NSComparisonPredicate evaluateWithObject:substitutionVariables:] + 306
7 Foundation 0x00210ead -[NSCompoundPredicateOperator evaluatePredicates:withObject:substitutionVariables:] + 292
8 Foundation 0x00210d57 -[NSCompoundPredicate evaluateWithObject:substitutionVariables:] + 254
9 Foundation 0x0020adac -[NSPredicate evaluateWithObject:] + 49
10 CoreData 0x0252ae08 -[NSManagedObjectContext executeFetchRequest:error:] + 1752
11 Wines 0x00021b27 -[MOListViewController listFRC] + 1034
12 Wines 0x000bb1e8 -[MOLocationSelectableListViewController numberOfSectionsInTableView:] + 36
13 UIKit 0x0061849c -[UITableViewRowData(UITableViewRowDataPrivate) _updateNumSections] + 111
14 UIKit 0x00618228 -[UITableViewRowData invalidateAllSections] + 66
15 UIKit 0x004d2880 -[UITableView(_UITableViewPrivate) _updateRowData] + 113
16 UIKit 0x004cbe9c -[UITableView noteNumberOfRowsChanged] + 105
17 UIKit 0x004d853c -[UITableView reloadData] + 773
18 UIKit 0x004d5724 -[UITableView layoutSubviews] + 42
19 QuartzCore 0x02a22481 -[CALayer layoutSublayers] + 177
20 QuartzCore 0x02a221b1 CALayerLayoutIfNeeded + 220
21 QuartzCore 0x02a220bd -[CALayer layoutIfNeeded] + 111
22 UIKit 0x0050c94b -[UIViewController window:willAnimateRotationToInterfaceOrientation:duration:] + 567
23 UIKit 0x004889bd -[UIWindow _setRotatableClient:toOrientation:duration:force:] + 4159
24 UIKit 0x006fa67b -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:] + 768
25 UIKit 0x0050f10d -[UIViewController presentModalViewController:withTransition:] + 2937
26 UIKit 0x00508402 -[UIViewController _tryRecursivelyPresentModalViewController:withTransition:] + 134
27 UIKit 0x005083c6 -[UIViewController _tryRecursivelyPresentModalViewController:withTransition:] + 74
28 UIKit 0x0050e8e6 -[UIViewController presentModalViewController:withTransition:] + 850
29 Wines 0x0002d7a9 -[MOViewController didSelectToOneSelectOneAtIndexPath:] + 2195
30 Wines 0x0002e843 -[MOViewController tableView:didSelectRowAtIndexPath:] + 4219
31 Wines 0x0005544f -[MOPriceViewController tableView:didSelectRowAtIndexPath:] + 1509
32 UIKit 0x004d4a48 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1140
33 UIKit 0x004cb32e -[UITableView _userSelectRowAtIndexPath:] + 219
34 Foundation 0x001e021a __NSFireDelayedPerform + 441
35 CoreFoundation 0x02eecf73 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
36 CoreFoundation 0x02eee5b4 __CFRunLoopDoTimer + 1364
37 CoreFoundation 0x02e4add9 __CFRunLoopRun + 1817
38 CoreFoundation 0x02e4a350 CFRunLoopRunSpecific + 208
39 CoreFoundation 0x02e4a271 CFRunLoopRunInMode + 97
40 GraphicsServices 0x035bf00c GSEventRunModal + 217
41 GraphicsServices 0x035bf0d1 GSEventRun + 115
42 UIKit 0x0046faf2 UIApplicationMain + 1160
43 Wines 0x00002814 main + 102
44 Wines 0x000027a5 start + 53
)
terminate called after throwing an instance of 'NSException'
Program received signal: “SIGABRT”.
here ya go...
BETWEEN operations are aggregate operations, and aggregate operations are not supported by Core Data. You'll need to turn this into:
NSPredicate *p = [NSPredicate predicateWithFormat:#"%K >= %# AND %K <= %#", keyPath, lowerBound, keyPath, upperBound];