swift - App crashing only on Device -
this strange crash happens running on devices, while in simulator works normally. debugging line line, noticed occurs while append string value array of doubles. convert double using extension:
extension string { func todouble() -> double? { return nsnumberformatter().numberfromstring(self)?.doublevalue } }
so crashing line is:
litros.append(temp_litros.todouble()!) //litros array , temp_litros string
the error:
fatal error: unexpectedly found nil while unwrapping optional value
i don't understand why works in simulator , doesn't on devices.
anyone have ideia happening here? in advance!
crash report:
incident identifier: 49f378a2-e7d9-4985-b208-99f529ae8813 crashreporter key: fe58b29412047d4d8980b9cb66ae017f1c2db7d5 hardware model: iphone7,2 process: nuvem [9479] path: /private/var/mobile/containers/bundle/application/8989627a-4064-428c-888b-c09f00a3ea0b/nuvem.app/nuvem identifier: br.com.gimenez.nuvem version: 1 (1.0) code type: arm-64 (native) parent process: launchd [1] date/time: 2015-07-23 18:07:12.529 -0300 launch time: 2015-07-23 18:07:05.037 -0300 os version: ios 8.4 (12h143) report version: 105 exception type: exc_breakpoint (sigtrap) exception codes: 0x0000000000000001, 0x0000000100659474 triggered thread: 0 thread 0 name: dispatch queue: com.apple.main-thread thread 0 crashed: 0 libswiftcore.dylib 0x0000000100659474 0x100598000 + 791668 1 nuvem 0x00000001000b5110 nuvem.graficoviewcontroller.viewdidload (nuvem.graficoviewcontroller)() -> () (graficoviewcontroller.swift:69) 2 nuvem 0x00000001000b5410 @objc nuvem.graficoviewcontroller.viewdidload (nuvem.graficoviewcontroller)() -> () (graficoviewcontroller.swift:0) 3 uikit 0x0000000188d14c14 -[uiviewcontroller loadviewifrequired] + 688 4 uikit 0x0000000188d14924 -[uiviewcontroller view] + 28 5 uikit 0x0000000188eb71ec -[uinavigationcontroller _startcustomtransition:] + 708 6 uikit 0x0000000188dc9e80 -[uinavigationcontroller _startdeferredtransitionifneeded:] + 464 7 uikit 0x0000000188dc9c4c -[uinavigationcontroller __viewwilllayoutsubviews] + 52 8 uikit 0x0000000188dc9bcc -[uilayoutcontainerview layoutsubviews] + 196 9 uikit 0x0000000188d116f0 -[uiview(calayerdelegate) layoutsublayersoflayer:] + 576 10 quartzcore 0x000000018864ddb4 -[calayer layoutsublayers] + 148 11 quartzcore 0x000000018864881c ca::layer::layout_if_needed(ca::transaction*) + 316 12 quartzcore 0x00000001886486c0 ca::layer::layout_and_display_if_needed(ca::transaction*) + 28 13 quartzcore 0x0000000188647e54 ca::context::commit_transaction(ca::transaction*) + 272 14 quartzcore 0x0000000188647bd4 ca::transaction::commit() + 524 15 quartzcore 0x00000001886412fc ca::transaction::observer_callback(__cfrunloopobserver*, unsigned long, void*) + 76 16 corefoundation 0x00000001842542a0 __cfrunloop_is_calling_out_to_an_observer_callback_function__ + 28 17 corefoundation 0x000000018425122c __cfrunloopdoobservers + 356 18 corefoundation 0x000000018425160c __cfrunlooprun + 832 19 corefoundation 0x000000018417d2d0 cfrunlooprunspecific + 392 20 graphicsservices 0x000000018dbd36f8 gseventrunmodal + 164 21 uikit 0x0000000188d7af3c uiapplicationmain + 1484 22 nuvem 0x00000001000ad9b8 main (appdelegate.swift:14) 23 libdyld.dylib 0x0000000196612a04 start + 0 thread 1 name: dispatch queue: com.apple.libdispatch-manager thread 1: 0 libsystem_kernel.dylib 0x0000000196710c24 kevent64 + 8 1 libdispatch.dylib 0x00000001965f5e6c _dispatch_mgr_invoke + 272 2 libdispatch.dylib 0x00000001965e7998 _dispatch_mgr_thread + 48 thread 2: 0 libsystem_kernel.dylib 0x000000019672bc78 __workq_kernreturn + 8 1 libsystem_pthread.dylib 0x00000001967c52d8 _pthread_wqthread + 988 2 libsystem_pthread.dylib 0x00000001967c4eec start_wqthread + 0 thread 3: 0 libsystem_kernel.dylib 0x000000019672bc78 __workq_kernreturn + 8 1 libsystem_pthread.dylib 0x00000001967c52d8 _pthread_wqthread + 988 2 libsystem_pthread.dylib 0x00000001967c4eec start_wqthread + 0 thread 4: 0 libsystem_kernel.dylib 0x000000019672bc78 __workq_kernreturn + 8 1 libsystem_pthread.dylib 0x00000001967c52d8 _pthread_wqthread + 988 2 libsystem_pthread.dylib 0x00000001967c4eec start_wqthread + 0 thread 5: 0 libsystem_kernel.dylib 0x000000019672bc78 __workq_kernreturn + 8 1 libsystem_pthread.dylib 0x00000001967c52d8 _pthread_wqthread + 988 2 libsystem_pthread.dylib 0x00000001967c4eec start_wqthread + 0 thread 6 name: com.apple.nsurlconnectionloader thread 6: 0 libsystem_kernel.dylib 0x0000000196710e0c mach_msg_trap + 8 1 libsystem_kernel.dylib 0x0000000196710c84 mach_msg + 68 2 corefoundation 0x0000000184253720 __cfrunloopservicemachport + 196 3 corefoundation 0x0000000184251674 __cfrunlooprun + 936 4 corefoundation 0x000000018417d2d0 cfrunlooprunspecific + 392 5 cfnetwork 0x0000000183c5a590 +[nsurlconnection(loader) _resourceloadloop:] + 436 6 foundation 0x000000018519ddb4 __nsthread__main__ + 1068 7 libsystem_pthread.dylib 0x00000001967c7dc4 _pthread_body + 160 8 libsystem_pthread.dylib 0x00000001967c7d20 _pthread_start + 156 9 libsystem_pthread.dylib 0x00000001967c4ef4 thread_start + 0 thread 7 name: com.apple.cfsocket.private thread 7: 0 libsystem_kernel.dylib 0x000000019672b498 __select + 8 1 corefoundation 0x0000000184259124 __cfsocketmanager + 668 2 libsystem_pthread.dylib 0x00000001967c7dc4 _pthread_body + 160 3 libsystem_pthread.dylib 0x00000001967c7d20 _pthread_start + 156 4 libsystem_pthread.dylib 0x00000001967c4ef4 thread_start + 0 thread 8: 0 libsystem_kernel.dylib 0x000000019672bc78 __workq_kernreturn + 8 1 libsystem_pthread.dylib 0x00000001967c52d8 _pthread_wqthread + 988 2 libsystem_pthread.dylib 0x00000001967c4eec start_wqthread + 0 thread 9: 0 libsystem_kernel.dylib 0x000000019672bc78 __workq_kernreturn + 8 1 libsystem_pthread.dylib 0x00000001967c52d8 _pthread_wqthread + 988 2 libsystem_pthread.dylib 0x00000001967c4eec start_wqthread + 0 thread 10: 0 libsystem_kernel.dylib 0x000000019672bc78 __workq_kernreturn + 8 1 libsystem_pthread.dylib 0x00000001967c52d8 _pthread_wqthread + 988 2 libsystem_pthread.dylib 0x00000001967c4eec start_wqthread + 0 thread 11: 0 libsystem_kernel.dylib 0x000000019672bc78 __workq_kernreturn + 8 1 libsystem_pthread.dylib 0x00000001967c52d8 _pthread_wqthread + 988 2 libsystem_pthread.dylib 0x00000001967c4eec start_wqthread + 0 thread 12: 0 libsystem_kernel.dylib 0x0000000196710e0c mach_msg_trap + 8 1 libsystem_kernel.dylib 0x0000000196710c84 mach_msg + 68 2 corefoundation 0x0000000184253720 __cfrunloopservicemachport + 196 3 corefoundation 0x0000000184251674 __cfrunlooprun + 936 4 corefoundation 0x000000018417d2d0 cfrunlooprunspecific + 392 5 foundation 0x00000001850b54c4 -[nsrunloop(nsrunloop) runmode:beforedate:] + 312 6 foundation 0x000000018510f80c -[nsrunloop(nsrunloop) run] + 92 7 nuvem 0x00000001000e64f8 +[pbafurlconnectionoperation networkrequestthreadentrypoint:] (pbafurlconnectionoperation.m:151) 8 foundation 0x000000018519ddb4 __nsthread__main__ + 1068 9 libsystem_pthread.dylib 0x00000001967c7dc4 _pthread_body + 160 10 libsystem_pthread.dylib 0x00000001967c7d20 _pthread_start + 156 11 libsystem_pthread.dylib 0x00000001967c4ef4 thread_start + 0 thread 0 crashed arm thread state (64-bit): x0: 0x0000000100588b80 x1: 0x00000001742f6a00 x2: 0x0000000000000008 x3: 0x0000000196765a74 x4: 0x000000016fd80e38 x5: 0x0000000000000020 x6: 0x0000000000000000 x7: 0x0000000000000fa0 x8: 0x00000001742f6b80 x9: 0x0000000000000000 x10: 0x0000000100584800 x11: 0x00000000005d0bda x12: 0x00000000fffffff2 x13: 0x00000001887c5480 x14: 0x0000000000000053 x15: 0x000000000000004d x16: 0x00000001967bda50 x17: 0x0000000000000000 x18: 0x0000000000000000 x19: 0x0000000144d85300 x20: 0x00000001978b7720 x21: 0x0000000000000008 x22: 0x0000000000000008 x23: 0x0000000000000000 x24: 0x0000000000000006 x25: 0x000000000004ffff x26: 0x0000000144e161d0 x27: 0x000000016fd810e9 x28: 0x0000000144d85300 fp: 0x000000016fd80ed0 lr: 0x0000000100659474 sp: 0x000000016fd80ec0 pc: 0x0000000100659474 cpsr: 0x60000000
by default nsnumberformatter
converts data according current locale settings. in case of simulator uses locale , "." decimal separator. in case of device uses "," separator can't convert data , numberfromstring
returns nil.
try this:
extension string { func todouble() -> double? { let formatter = nsnumberformatter() formatter.locale = nslocale(localeidentifier: "en_us") return formatter.numberfromstring(self)?.doublevalue } }
Comments
Post a Comment