Reputation: 1470
I'm writing an app in Swift 3 using Xcode 8.3.2. My app runs fine in the Simulator but I get an ugly error message when I try to run it on my iPhone (iOS 10.3.1):
libswiftCore.dylib`function signature specialization <preserving fragile attribute, Arg[2] = Dead, Arg[3] = Dead> of Swift._fatalErrorMessage (Swift.StaticString, Swift.StaticString, file : Swift.StaticString, line : Swift.UInt, flags : Swift.UInt32) -> Swift.Never:
0x1005203d0 <+0>: stp x26, x25, [sp, #-0x50]!
0x1005203d4 <+4>: stp x24, x23, [sp, #0x10]
0x1005203d8 <+8>: stp x22, x21, [sp, #0x20]
0x1005203dc <+12>: stp x20, x19, [sp, #0x30]
0x1005203e0 <+16>: stp x29, x30, [sp, #0x40]
0x1005203e4 <+20>: add x29, sp, #0x40 ; =0x40
0x1005203e8 <+24>: mov x19, x6
0x1005203ec <+28>: mov x20, x5
0x1005203f0 <+32>: mov x21, x4
0x1005203f4 <+36>: mov x22, x3
0x1005203f8 <+40>: mov x23, x2
0x1005203fc <+44>: mov x24, x1
0x100520400 <+48>: mov x25, x0
0x100520404 <+52>: adr x8, #0xf11fc ; protocol descriptor for Swift._DefaultCustomPlaygroundQuickLookable + 136
0x100520408 <+56>: nop
0x10052040c <+60>: add x0, x8, #0x10 ; =0x10
0x100520410 <+64>: mov w1, #0x28
0x100520414 <+68>: orr w2, wzr, #0x7
0x100520418 <+72>: bl 0x100520750 ; swift_rt_swift_allocObject
0x10052041c <+76>: mov x8, x0
0x100520420 <+80>: stp x22, x21, [x8, #0x10]
0x100520424 <+84>: strb w20, [x8, #0x20]
0x100520428 <+88>: str w19, [x8, #0x24]
0x10052042c <+92>: adr x3, #0x40440 ; partial apply forwarder for Swift.(_fatalErrorMessage (Swift.StaticString, Swift.StaticString, file : Swift.StaticString, line : Swift.UInt, flags : Swift.UInt32) -> Swift.Never).(closure #2)
0x100520430 <+96>: nop
0x100520434 <+100>: mov x0, x25
0x100520438 <+104>: mov x1, x24
0x10052043c <+108>: mov x2, x23
0x100520440 <+112>: mov x4, x8
0x100520444 <+116>: bl 0x1004014dc ; function signature specialization <preserving fragile attribute, Arg[1] = [Closure Propagated : reabstraction thunk helper from @callee_owned (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) -> () to @callee_owned (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) -> (@out ()), Argument Types : [@callee_owned (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) -> ()]> of generic specialization <preserving fragile attribute, ()> of Swift.StaticString.withUTF8Buffer <A> ((Swift.UnsafeBufferPointer<Swift.UInt8>) -> A) -> A
-> 0x100520448 <+120>: brk #0x1
I set an exception breakpoint that led me to this bit of code:
if let defaultFormula = dataManager.fetchDefaultFormula(moc) {
self.formula = defaultFormula.first! <<< Unexpectedly found nil...
}
and here is the function it's calling:
func fetchDefaultFormula(_ moc: NSManagedObjectContext) -> [Formula]? {
let defaultFormulaID = UserDefaults.formula()
let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "Formula")
let filterPredicate = NSPredicate(format: "uuid = [c] %@", defaultFormulaID)
fetchRequest.predicate = filterPredicate
do {
return try moc.fetch(fetchRequest) as? [Formula]
} catch {
fatalError("There was an error fetching the lifts")
}
return nil
}
The fetch request is returning 0 values so it's clear why I get the exception when I force unwrap it. However, the object property 'formula' must have a value. The first thing the app does is check to see if the default data (like the available formulas) exists in the persistent store and if it doesn't, it adds it. I've reset the Simulator and it dutifully adds them but it seems that this isn't happening on the iPhone. If there's a way for me to determine whether or not the records are being added to the store when running it on the iPhone, please enlighten me.
I've found a few SO threads in which others have experienced this cryptic error (the big, ugly one, not the unexpected nil) and I've tried all of the remedies suggested:
I don't know where to go from here having exhausted all of the suggestions I've been able to find.
Any suggestions are greatly appreciated.
Upvotes: 1
Views: 329
Reputation: 1470
Well, I guess there was one thing I didn't try - uninstalling the app from my phone first, then build and run it on the phone.
So I don't really know what the root cause was, but at least this resolved the problem.
Upvotes: 2