In my mac OS X application, I am getting this EXC_BAD_ACCESS signal in Core Data part (NSPredicate).
Code for reference:
[self.managedObjectContext reset];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[self.managedObjectContext setMergePolicy:NSMergeByPropertyObjectTrumpMergePolicy];
//Setting Entity to be Queried
NSEntityDescription *entity = [NSEntityDescription entityForName:#"FileTable"
inManagedObjectContext:self.managedObjectContext];
[fetchRequest setSortDescriptors:[NSArray arrayWithObject:[[NSSortDescriptor alloc] initWithKey:#"_pk" ascending:NO]]];
[fetchRequest setEntity:entity];
NSError* error;
NSString *uuid = uniqueId;
NSPredicate *pred = [NSPredicate predicateWithFormat:#"uuid = %#", uuid];
[fetchRequest setPredicate:pred];
// Query on managedObjectContext With Generated fetchRequest
NSArray *fetchedRecords = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];
// NSLog(#"fetchedRecords %#",fetchedRecords);
// Returning Fetched Records
return fetchedRecords;
I caught the stack trace for the above scenario
(
0 WEPA-PrintApp 0x000000010a235969 WEPA-PrintApp + 47465
1 CoreFoundation 0x00007fff9216acbc __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
2 CoreFoundation 0x00007fff9205c1b4 _CFXNotificationPost + 3140
3 Foundation 0x00007fff8c528ea1 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
4 AppKit 0x00007fff8f95725b -[NSApplication _postDidFinishNotification] + 291
5 AppKit 0x00007fff8f956fc6 -[NSApplication _sendFinishLaunchingNotification] + 191
6 AppKit 0x00007fff8f953dc6 -[NSApplication(NSAppleEventHandling) _handleAEOpenEvent:] + 574
7 AppKit 0x00007fff8f953805 -[NSApplication(NSAppleEventHandling) _handleCoreEvent:withReplyEvent:] + 244
8 Foundation 0x00007fff8c548458 -[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:] + 290
9 Foundation 0x00007fff8c5482c9 _NSAppleEventManagerGenericHandler + 102
10 AE 0x00007fff9047a99c _Z20aeDispatchAppleEventPK6AEDescPS_jPh + 531
11 AE 0x00007fff9047a719 _ZL25dispatchEventAndSendReplyPK6AEDescPS_ + 31
12 AE 0x00007fff9047a623 aeProcessAppleEvent + 295
13 HIToolbox 0x00007fff93e1b37e AEProcessAppleEvent + 56
14 AppKit 0x00007fff8f94fec6 _DPSNextEvent + 2665
15 AppKit 0x00007fff8f94efd0 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 194
16 AppKit 0x00007fff8f942f73 -[NSApplication run] + 594
17 AppKit 0x00007fff8f92e424 NSApplicationMain + 1832
18 WEPA-PrintApp 0x000000010a250f96 WEPA-PrintApp + 159638
19 libdyld.dylib 0x00007fff917ae5c9 start + 1
)
This crash occurs not all the time. And uuid here is NSString. Can any one provide the solution to accomplish the issue?
Related
Is is a bug of iOS 15 itself?
What can I do to fix this?
It crashs when [UIPrintPreviewViewController reloadVisibleItems]
It only happends on iOS from 15.0.0 to 15.5.0 so far
When will UIPrintPreviewViewController reloadVisibleItems ?
We can't even reproduce the crash, but we get lots crash reports on Firebase.
Source code
UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];
if (controller) {
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.duplex = UIPrintInfoDuplexLongEdge;
controller.printInfo = printInfo;
controller.printingItems = [self dataList];
LYWeakifySelf;
void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
^(UIPrintInteractionController *controller, BOOL completed, NSError *error) {
};
[controller presentAnimated:YES completionHandler:completionHandler];
}
- (NSArray<NSData *> *)dataList {
NSMutableArray *dataList = [NSMutableArray array];
[self enumerateDataUsingBlock:^(NSData *data, NSString *fileName) {
[dataList addObject:data];
}];
return dataList;
}
Crash info on Firebase
Fatal Exception: NSInternalInconsistencyException.
attempt to delete item 1 from section 0 which only contains 0 items before the update.
Stack trace
0 CoreFoundation __exceptionPreprocess
1 libobjc.A.dylib objc_exception_throw
2 Foundation _userInfoForFileAndLine
3 UIKitCore -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:animator:collectionViewAnimator:]
4 UIKitCore -[UICollectionView _updateRowsAtIndexPaths:updateAction:updates:]
5 UIKitCore -[UICollectionView reloadItemsAtIndexPaths:]
6 UIKitCore -[UIPrintPreviewViewController reloadVisibleItems:]
7 UIKitCore __58-[UIPrintPreviewViewController updateLayoutWithPdfUpdate:]_block_invoke_2
8 Foundation __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__
9 Foundation -[NSBlockOperation main]
10 Foundation __NSOPERATION_IS_INVOKING_MAIN__
11 Foundation -[NSOperation start]
12 Foundation __NSOPERATIONQUEUE_IS_STARTING_AN_OPERATION__
13 Foundation __NSOQSchedule_f
14 libdispatch.dylib _dispatch_block_async_invoke2
15 libdispatch.dylib _dispatch_client_callout
16 libdispatch.dylib _dispatch_main_queue_drain
17 libdispatch.dylib _dispatch_main_queue_callback_4CF
18 CoreFoundation __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
19 CoreFoundation __CFRunLoopRun
20 CoreFoundation CFRunLoopRunSpecific
21 GraphicsServices GSEventRunModal
22 UIKitCore -[UIApplication _run]
23 UIKitCore UIApplicationMain
24 EverLens main.m - Line 14
main + 14
I'm looking into a somewhat frequent crash reported in my application's Crashlytics console.
One of the many examples I have has the following crashed thread stacktrace:
#11. Crashed: com.apple.root.default-qos
0 libobjc.A.dylib 0x22f3fa86 objc_msgSend + 5
1 Foundation 0x23ee3005 -[NSString caseInsensitiveCompare:] + 28
2 Foundation 0x23ed10bd _NSCompareObject + 28
3 Foundation 0x23ed109d _NSSortFunctionOne + 120
4 CoreFoundation 0x2373e6a3 __CFSimpleMergeSort + 114
5 CoreFoundation 0x2373e6c5 __CFSimpleMergeSort + 148
6 CoreFoundation 0x2373e6d9 __CFSimpleMergeSort + 168
7 CoreFoundation 0x2373e6c5 __CFSimpleMergeSort + 148
8 CoreFoundation 0x2373e6d9 __CFSimpleMergeSort + 168
9 CoreFoundation 0x2368ac35 CFSortIndexes + 404
10 CoreFoundation 0x2368c241 CFMergeSortArray + 176
11 Foundation 0x23ed0a9d _sortedObjectsUsingDescriptors + 456
12 Foundation 0x23f9c9fb -[NSSet(NSKeyValueSorting) sortedArrayUsingDescriptors:] + 510
13 MyApp 0x6d431 __24-[MyApp refresh]_block_invoke (MyApp.m:247)
14 CoreFoundation 0x23769499 __NSArrayEnumerate + 372
15 CoreFoundation 0x236e6c3b -[NSArray enumerateObjectsWithOptions:usingBlock:] + 62
16 MyApp 0x6d17d -[MyApp refresh] (MyApp.m:263)
17 MyApp 0xa97eb __52-[MyAppRequest updateAfterNotification:]_block_invoke (MyAppRequest.m:1175)
18 libdispatch.dylib 0x23307cbf _dispatch_call_block_and_release + 10
19 libdispatch.dylib 0x233136a1 _dispatch_root_queue_drain + 1572
20 libdispatch.dylib 0x2331307b _dispatch_worker_thread3 + 94
21 libsystem_pthread.dylib 0x234a6e0d _pthread_wqthread + 1024
22 libsystem_pthread.dylib 0x234a69fc start_wqthread + 8
Other instances of the crash occur in the same app code (in the refresh method of MyApp class), but during different parts of the CoreFoundation sortedArrayUsingDescriptors method logic. For example, another crash example stacktrace has:
0 libobjc.A.dylib 0x1823cdb90 objc_msgSend + 16
1 CoreFoundation 0x182c42738 CFStringCompareWithOptionsAndLocale + 232
2 Foundation 0x183644840 _NSCompareObject + 64
3 CoreFoundation 0x182d150f4 __CFSimpleMergeSort + 196
4 CoreFoundation 0x182d15124 __CFSimpleMergeSort + 244
5 CoreFoundation 0x182d15124 __CFSimpleMergeSort + 244
6 CoreFoundation 0x182d15124 __CFSimpleMergeSort + 244
7 CoreFoundation 0x182d1513c __CFSimpleMergeSort + 268
8 CoreFoundation 0x182d15124 __CFSimpleMergeSort + 244
9 CoreFoundation 0x182d15124 __CFSimpleMergeSort + 244
10 CoreFoundation 0x182d15124 __CFSimpleMergeSort + 244
11 CoreFoundation 0x182c3b738 CFSortIndexes + 472
12 CoreFoundation 0x182c3cf58 CFMergeSortArray + 220
13 Foundation 0x1836440f8 _sortedObjectsUsingDescriptors + 564
14 Foundation 0x183725120 -[NSSet(NSKeyValueSorting) sortedArrayUsingDescriptors:] + 564
15 MyApp 0x10006f264 __24-[MyApp refresh]_block_invoke (MyApp.m:247)
The app code in refresh is:
- (void)refresh {
NSArray *products = [self getProducts];
NSMutableArray *validProducts = [NSMutableArray array];
[products enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
Product *prod = obj;
// Convert to internal native format (MyAppProduct) for business reasons...
MyAppProduct *myAppProd = [[MyAppProduct alloc] init];
myAppProd.ID = prod.id;
myAppProd.name = prod.name;
NSArray *subProds = [prod.subProds sortedArrayUsingDescriptors:#[[NSSortDescriptor sortDescriptorWithKey:#"subProds" ascending:NO]]];
NSMutableArray *validSubProds = [NSMutableArray array];
[subProds enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
SubProd *subProd = obj;
// Convert to internal native format (MyAppSubProduct) for business reasons...
MyAppSubProduct *myAppSubProd = [[MyAppSubProduct alloc] initWithSubProd:subProd];
[validSubProds addObject:myAppSubProd];
}];
myAppProd.subProds = validSubProds;
myAppProd.count = [product.count integerValue];
// Add to array
[validProducts addObject:myAppProd];
}];
// Apply array to self
_products = validProducts
}
where getProducts is:
- (NSArray*)getProducts {
NSFetchRequest *productFetchRequest = [NSFetchRequest fetchRequestWithEntityName:#"Products"];
// Filter
NSMutableArray *productsPredicates = [NSMutableArray array];
[productsPredicates addObject:[NSPredicate predicateWithFormat:#"life_uid == %#", req.lifeUid]];
[productsPredicates addObject:[NSPredicate predicateWithFormat:#"hidden == %#", #NO]];
[productFetchRequest setPredicate:[NSCompoundPredicate andPredicateWithSubpredicates:productsPredicates]];
// Sort
NSSortDescriptor *sortProductsByName = [NSSortDescriptor sortDescriptorWithKey:#"name" ascending:YES];
[productFetchRequest setSortDescriptors:#[sortProductsByName]];
[productFetchRequest setReturnsObjectsAsFaults:NO];
[productFetchRequest setRelationshipKeyPathsForPrefetching:#[#"subprods", #"subprods.special"]];
NSManagedObjectContext *moc = [MyAppCoreDataController sharedController].mainManagedObjectContext;
NSError *error = nil;
NSArray *products = [moc executeFetchRequest:productFetchRequest error:&error];
if (error) {
NSLog(#"Error fetching products %#", error);
}
return products;
}
And refresh is being called like so:
- (void)updateAfterNotification:(NSNotification *)notification {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[[MyApp instance] refresh];
});
}
Most likely it's because you're not handling Core Data concurrency correctly. When you create a managed object context using NSPrivateQueueConcurrencyType or NSMainQueueConcurrencyType, you must put all Core Data access inside a call to performBlock or performBlockAndWait. That includes fetches as well as accessing attribute values of fetched objects.
You're using dispatch_async, which is not the right way to handle concurrency with Core Data. You should switch to using performBlock or performBlockAndWait.
when I execute this line of code in iOS 8.3 this line crashes:
NSArray *results = [self executeFetchRequest:request inContext:context];
here is the entire function which fails:
+ (id) executeFetchRequestAndReturnFirstObject:(NSFetchRequest *)request inContext:(NSManagedObjectContext *)context
{
[request setFetchLimit:1];
NSArray *results = [self executeFetchRequest:request inContext:context];
if ([results count] == 0)
{
return nil;
}
return [results objectAtIndex:0];
}
the above function is called by:
+ (id)findFirstByAttribute:(NSString *)attribute withValue:(id)searchValue inContext:(NSManagedObjectContext *)context
{
NSFetchRequest *request = [self requestFirstByAttribute:attribute withValue:searchValue inContext:context];
[request setPropertiesToFetch:[NSArray arrayWithObject:attribute]];
return [self executeFetchRequestAndReturnFirstObject:request inContext:context];
}
It is worth noting that I am very new to iOS programming so please go easy on me, the question may not be the best and there may not be much backing code but this is due to my lack of knowledge in iOS. My android questions are generally much better than this :P If I am able to add any more detail, I will add more as I can, the crash log is below
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Bad fetch request
(NSManagedObjectResultType not compatible with contents of
propertiesToFetch)'
* First throw call stack: ( 0 CoreFoundation 0x0000000111d7dc65 exceptionPreprocess + 165 1 libobjc.A.dylib
0x0000000110fafbb7 objc_exception_throw + 45 2 CoreData
0x00000001112ecb6e -[NSSQLGenerator
newSQLStatementForRequest:ignoreInheritance:countOnly:nestingLevel:] +
1646 3 CoreData 0x00000001112d8dc4
-[NSSQLAdapter _statementForFetchRequest:ignoreInheritance:countOnly:nestingLevel:] + 244 4 CoreData 0x00000001111f0e0c
-[NSSQLAdapter _newSelectStatementWithFetchRequest:ignoreInheritance:] + 316 5 CoreData 0x00000001111f0a86 -[NSSQLCore newRowsForFetchPlan:] + 118 6 CoreData 0x00000001111f033c -[NSSQLCore objectsForFetchRequest:inContext:] +
524 7 CoreData 0x00000001111efdbb
-[NSSQLCore executeRequest:withContext:error:] + 299 8 CoreData 0x00000001112caa6c __65-[NSPersistentStoreCoordinator
executeRequest:withContext:error:]_block_invoke + 3356 9 CoreData
0x00000001112d3c30 gutsOfBlockToNSPersistentStoreCoordinatorPerform +
192 10 libdispatch.dylib 0x0000000114e29614
_dispatch_client_callout + 8 11 libdispatch.dylib 0x0000000114e0f002 _dispatch_barrier_sync_f_invoke + 365 12 CoreData
0x00000001112c5245 _perform + 197 13 CoreData
0x00000001111efa58 -[NSPersistentStoreCoordinator
executeRequest:withContext:error:] + 504 14 CoreData
0x00000001111ee2ca -[NSManagedObjectContext
executeFetchRequest:error:] + 586 15 HawkExpress
0x000000010e52438e +[NSManagedObject(MagicalRecord)
executeFetchRequest:inContext:] + 62 16 HawkExpress
0x000000010e52446e +[NSManagedObject(MagicalRecord)
executeFetchRequestAndReturnFirstObject:inContext:] + 78 17
HawkExpress 0x000000010e5261fc
+[NSManagedObject(MagicalRecord) findFirstByAttribute:withValue:inContext:] + 140 18 HawkExpress
0x000000010e526274 +[NSManagedObject(MagicalRecord)
findFirstByAttribute:withValue:] + 100 19 HawkExpress
0x000000010e52aa54 +[FavouritesManager doesFavouriteExist:] + 84 20
HawkExpress 0x000000010e4de4a7
-[BookCabViewController tableView:cellForRowAtIndexPath:] + 2087 21 UIKit 0x00000001124b9a28 -[UITableView
_createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 508 22 UIKit 0x0000000112498248 -[UITableView
_updateVisibleCellsNow:isRecursive:] + 2853 23 UIKit 0x00000001124ae8a9 -[UITableView layoutSubviews] + 210 24 UIKit
0x0000000112438a2b -[UIView(CALayerDelegate) layoutSublayersOfLayer:]
+ 536 25 QuartzCore 0x000000010fdfbec2 -[CALayer layoutSublayers] + 146 26 QuartzCore 0x000000010fdf06d6 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE +
380 27 QuartzCore 0x000000010fdf0546
_ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24 28 QuartzCore 0x000000010fd5c886
_ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242 29 QuartzCore 0x000000010fd5da3a
_ZN2CA11Transaction6commitEv + 462 30 QuartzCore 0x000000010fd5e0eb
_ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 89 31 CoreFoundation 0x0000000111cb0ca7
__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 23 32 CoreFoundation 0x0000000111cb0c00
__CFRunLoopDoObservers + 368 33 CoreFoundation 0x0000000111ca6a33 __CFRunLoopRun + 1123 34 CoreFoundation
0x0000000111ca6366 CFRunLoopRunSpecific + 470 35 GraphicsServices
0x0000000114a34a3e GSEventRunModal + 161 36 UIKit
0x00000001123b8900 UIApplicationMain + 1282 37 HawkExpress
0x000000010e4baa23 main + 99 38 libdyld.dylib
0x0000000114e5d145 start + 1 ) libc++abi.dylib: terminating with
uncaught exception of type NSException (lldb)
You need to check if the NSArray results is nil before you can do a count.
if (array != nil) {
NSUInteger count = [array count]; // May be 0 if the object has been deleted.
//
}
else {
// Deal with error.
}
See https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CoreData/Articles/cdFetching.html
Your NSFetchRequest object is probably not constructed correctly.
Here is a valid NSFetchRequest example. Find plenty more by googling "NSFetchRequest example".
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSPredicate *predicate = [NSPredicate predicateWithFormat:#"name == %#", aTitle]; //<----- (a)
[request setEntity:[NSEntityDescription entityForName:#"Person" inManagedObjectContext:moc]];
[request setPredicate:predicate];
Be careful at (a), the string must strictly follow the predicate format string pattern (see NSPrediate class reference), name must be a property of Person entity in your managed object model
And the problem is in this part
NSFetchRequest *request = [self requestFirstByAttribute:attribute withValue:searchValue inContext:context];
[request setPropertiesToFetch:[NSArray arrayWithObject:attribute]];
So, post the code for method [self requestFirstByAttribute... ] if still not resolved.
tried to comment out the line [request setPropertiesToFetch:[NSArray arrayWithObject:attribute]];?
'Bad fetch request (NSManagedObjectResultType not compatible with contents of propertiesToFetch)' means, that you seem to expect the default NSFetchRequestResultType (NSManagedObjectResultType). But you request not to fetch the complete Entity, but only ONE attribute (why, just by the way? Your method provide an expected value and gives only one attribute to fetch).
My solution to this:
- (id)findEntityNamed:(NSString*)entity withKeyPath:(NSString*)path equalTo:(id)value
{
NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:[NSEntityDescription entityForName:entity
inManagedObjectContext:context]];
NSPredicate* predicate =
[NSComparisonPredicate predicateWithLeftExpression:[NSExpression expressionForKeyPath:path]
rightExpression:[NSExpression expressionForConstantValue:value]
modifier:NSDirectPredicateModifier
type:NSEqualToPredicateOperatorType
options:0];
[fetchRequest setPredicate:predicate];
[fetchRequest setFetchLimit:1]; // ONLY 1 OBJECT IS FETCHED!
NSError* err = nil;
NSArray* results = [context executeFetchRequest:fetchRequest error:&err];
[fetchRequest release];
if( err )
{
// do logging stuff etc.
}
if( [results count] < 1 )
return nil;
return [results lastObject];
}
you can try this and tell if this is more like you was looking for
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]];
I have this crash while executing a fetch request, but from the crash report it is clear that the cause for the crash is that the predicate is nil. I have added a check for the case the startDate is nil. Is there any other potential cause for the invalid predicate I should take care of?
NSFetchRequest *calRequest = [NSFetchRequest fetchRequestWithEntityName:#"Calendar"];
calRequest.predicate = [NSPredicate predicateWithFormat:#"date >= %#", startDate];
calRequest.sortDescriptors = #[[NSSortDescriptor sortDescriptorWithKey:#"date" ascending:YES]];
NSError *error = nil;
NSArray *results = [appDelegate.managedObjectContext executeFetchRequest:calRequest error:&error];
Crash report
Thread : Fatal Exception: NSInvalidArgumentException
0 CoreFoundation 0x30534f03 __exceptionPreprocess + 130
1 libobjc.A.dylib 0x3acc9ce7 objc_exception_throw + 38
2 CoreData 0x30289f17 -[NSComparisonPredicate(_NSCoreDataSQLPredicateCategories) minimalFormInContext:] + 926
3 CoreData 0x3028952b -[NSSQLGenerator initializeContextForFetchRequest:ignoreInheritance:nestingLevel:] + 538
4 CoreData 0x30288f9f -[NSSQLGenerator newSQLStatementForFetchRequest:ignoreInheritance:countOnly:nestingLevel:] + 34
5 CoreData 0x30288e3f -[NSSQLAdapter _newSelectStatementWithFetchRequest:ignoreInheritance:] + 406
6 CoreData 0x30288aa3 -[NSSQLCore newRowsForFetchPlan:] + 114
7 CoreData 0x302881e7 -[NSSQLCore objectsForFetchRequest:inContext:] + 698
8 CoreData 0x30287c8b -[NSSQLCore executeRequest:withContext:error:] + 446
9 CoreData 0x30287539 -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 2892
10 CoreData 0x3028593b -[NSManagedObjectContext executeFetchRequest:error:] + 614
11 MyApp 0x0010b769 -[Calendar calendarLoad] (Calendar.m:152)
...