My app uses core data. I have recently upgraded to Xcode 10.2 and swift 5 and since then I am receiving random crashes that has something to do with core data.
From what I have gathered this happened when trying to change Core Data from a background thread (After pulling new data from the server).
I receive the following error message
2019-03-31 14:49:17.358685+0300 LeaderMES[24226:595701] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSTaggedDate objectForKey:]: unrecognized selector sent to instance 0x8000000000000000'
Or
2019-03-31 14:37:04.676485+0300 LeaderMES[23749:583097] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_NSCoreDataTaggedObjectID objectForKey:]: unrecognized selector sent to instance 0x8000000000000000'
Not only my code used to work, this instance number looks suspicious
My app is connected to crashlytics which caught one of these errors. Here is the stack trace it caught:
Fatal Exception: NSInvalidArgumentException
0 CoreFoundation 0x1086f86e3 (Missing)
1 libobjc.A.dylib 0x10771bac5 objc_exception_throw
2 CoreFoundation 0x108716ab4 (Missing)
3 CoreFoundation 0x1086fd443 (Missing)
4 CoreFoundation 0x1086ff238 (Missing)
5 libswiftCore.dylib 0x109914dcc (Missing)
6 libswiftCore.dylib 0x109b407b9 (Missing)
7 LeaderMES 0x105080a8d closure #1 in LMNotificationRepository.loadNotificationHistory(forFactory:successCompletion:errorCompletion:) (LMNotificationRepository.swift:360)
8 LeaderMES 0x105091271 partial apply for closure #1 in LMNotificationRepository.loadNotificationHistory(forFactory:successCompletion:errorCompletion:) (<compiler-generated>)
9 LeaderMES 0x10510b872 closure #1 in LMHttpProvider.procedeRequest(_:completionHandler:) (LMHTTPProvider.swift:299)
10 LeaderMES 0x10510e381 partial apply for closure #1 in LMHttpProvider.procedeRequest(_:completionHandler:) (<compiler-generated>)
11 LeaderMES 0x1050ce176 thunk for @escaping @callee_guaranteed (@guaranteed Data?, @guaranteed NSURLResponse?, @guaranteed Error?) -> () (<compiler-generated>)
12 CFNetwork 0x10adf6178 (Missing)
13 CFNetwork 0x10ae0cc56 (Missing)
14 Foundation 0x10666f412 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__
15 Foundation 0x10666f31a -[NSBlockOperation main]
16 Foundation 0x10666c1f4 -[__NSOperationInternal _start:]
17 Foundation 0x106671f5b __NSOQSchedule_f
18 libdispatch.dylib 0x10a539ccf (Missing)
19 libdispatch.dylib 0x10a53ad02 (Missing)
20 libdispatch.dylib 0x10a53d6be (Missing)
21 libdispatch.dylib 0x10a53cd49 (Missing)
22 libdispatch.dylib 0x10a549ad3 (Missing)
23 libdispatch.dylib 0x10a54a330 (Missing)
24 libsystem_pthread.dylib 0x10a91c6b3 (Missing)
25 libsystem_pthread.dylib 0x10a91c3fd (Missing)
What are all the missing dylibs mentioned?
I have tried moving all Core Data activity to main thread using DispatchQueue with no luck.
I have removed the app from simulator and reinstalled it and so far the crash doesn't repeat. Any ideas as to what caused this crash?
It looks like a bug for non-optimized builds done in Xcode 10.2. I don't use a Core Data in my app and it also crashes with
-[xxx objectForKey:]: unrecognized selector sent to instance 0x8000000000000000'
XXX sometimes is __NSTaggedDate
, sometimes it is another type but the address is always 0x8000000000000000
. Debugger stops on a line when I access a valid dictionary by a valid key and it is not helpful at all. The app stops crashing when I changed optimization to Optimise for speed -O
for debug scheme.
A similar issue was happening for me when I was changing and accessing an object from two different threads (in two different places in my code) at the same time, address must have been changing. I solved by using a DispatchQueue to sync the access to this object
var lock: DispatchQueue = DispatchQueue.init(label: "")
lock.sync{ access object }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With