2016-09-17 36 views
1

我一直在努力應對一場不應該發生的非常奇怪的崩潰。我通過Hockeyapp收到崩潰報告,它不斷報告崩潰,應用程序不應該崩潰。我已經面對這個問題已經1周了。崩潰在哪裏應該不會在Swift中崩潰(「if,let,where」語句)

這是崩潰報告的代碼

0 TeacherBox       0x00000001000864f0 TeacherBox.RequestLessonViewController.loadExistingRequests() ->() (RequestLessonViewController.swift:755) 
1 TeacherBox       0x0000000100086514 @objc TeacherBox.RequestLessonViewController.loadExistingRequests() ->() (RequestLessonViewController.swift:0) 
2 TeacherBox       0x0000000100086a84 function signature specialization <Arg[0] = Dead> of TeacherBox.RequestLessonViewController.viewDidAppear (Swift.Bool) ->() (RequestLessonViewController.swift:122) 
3 TeacherBox       0x000000010007e570 @objc TeacherBox.RequestLessonViewController.viewDidAppear (Swift.Bool) ->() (RequestLessonViewController.swift:0) 
4 UIKit        0x00000001895b84dc -[UIViewController _setViewAppearState:isAnimating:] + 844 
5 UIKit        0x00000001895b8a40 -[UIViewController _endAppearanceTransition:] + 216 
6 UIKit        0x0000000189671038 -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:] + 1232 
7 UIKit        0x0000000189742198 __49-[UINavigationController _startCustomTransition:]_block_invoke + 228 
8 UIKit        0x00000001896c7cc4 -[_UIViewControllerTransitionContext completeTransition:] + 112 
9 UIKit        0x00000001898181ec __53-[_UINavigationParallaxTransition animateTransition:]_block_invoke.97 + 708 
10 UIKit        0x00000001895d9214 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 488 
11 UIKit        0x00000001895d8d38 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 308 
12 UIKit        0x00000001895d8b78 -[UIViewAnimationState animationDidStop:finished:] + 156 

線:

if let booking = rescheduleBooking where booking.confirmed! == 0 { 
    existingRequests.append(booking) 
} 

線755是if語句。在swift中的「if,let,where」語句中,「let」檢查rescheduleBooking是否存在,如果它存在並被賦值,那麼where語句會被執行....對嗎?...無論如何,我測試過本地在我的設備和模擬器,它不會在那裏崩潰,無論變量的值...它發生在一個不同的設備,我手上沒有..

請,如果你有任何建議,或者,如果我沒有正確理解「如果,讓我們放在哪裏」條款,我將非常感謝您的幫助和評論。

謝謝..

+0

刪除'let'和嘗試。 –

+5

這將崩潰,如果'booking.confirmed'爲零,因爲你有力量解開它 – Paulw11

回答

1

你的理解:「如果,讓其中」條款是正確的,但你必須有記,if let booking = rescheduleBooking可以確保rescheduleBookingnil,然後將其分配給booking。現在,儘管booking不是nil,但並不保證booking.confirmed不會是nil,因此如果它是nil,並且您強制展開它,則會導致崩潰。

您可以添加其他讓利,以確保booking.confirmednil

if let booking = rescheduleBooking, let bookingConfirmed = booking.confirmed where bookingConfirmed == 0 { 
    existingRequests.append(booking) 
} 
+0

嗨,謝謝你的回答..現在確認不是可選了,但它繼續崩潰在那裏... –

+0

我們應該工作從與您的代碼相關的崩潰中的最低行開始,這是'3 TeacherBox 0x000000010007e570 @objc TeacherBox.RequestLessonViewController.viewDidAppear(Swift.Bool) - >()(RequestLessonViewController.swift:0) '。你能否包括該行的相關代碼? –

+0

如果您可以請從崩潰報告中包含完整的崩潰報告和第2行和第1行的相關代碼,那麼我可以看到發生了什麼事情以找出導致崩潰的原因。 –

相關問題