2016-09-17 69 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行的相关代码,那么我可以看到发生了什么事情以找出导致崩溃的原因。 –