1

I've been struggling with a very weird crash that should not happen at all. I receive the crash report via Hockeyapp, it keeps reporting a crash in a line that the app should not crash at all. I've been facing this problem for already 1 week.

This is the crash report

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

Lines of code:

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

The line 755 is the if statement. In a "if, let, where" statement in swift, "let" checks for the existence of rescheduleBooking, if it exists and is assigned, the where statements is executed.... Am I right?... Anyway, I tested locally in my device and simulator and it doesn't crash there, no matter the values of the vars... it is happening in a different device that I don't have on hands..

Please, if you have any advice, or maybe, if I didn't understand correctly the "if, let where" clause, I will be very grateful of your help and comments.

Thanks..

Adrián Rivero
  • 161
  • 1
  • 9

1 Answers1

1

Your Understanding of "if-let where" clause is correct, but you have to have in mind that if let booking = rescheduleBooking makes sure that rescheduleBooking is not nil and then assigns it to booking. Now even though booking is not nil that does not guarantee that booking.confirmed won't be nil so if it's nil and you force unwrap it it will cause a crash.

You can add another let to make sure booking.confirmed is not nil:

if let booking = rescheduleBooking, let bookingConfirmed = booking.confirmed where bookingConfirmed == 0 {
    existingRequests.append(booking)
}
Swifty
  • 3,730
  • 1
  • 18
  • 23
  • Hi, thanks for your answer.. now confirmed is not an optional anymore, but it continue crashing there... – Adrián Rivero Sep 18 '16 at 10:46
  • We should work our way up from the lowest line in the crash that is related to your code which is `3 TeacherBox 0x000000010007e570 @objc TeacherBox.RequestLessonViewController.viewDidAppear (Swift.Bool) -> () (RequestLessonViewController.swift:0) `. Can you please include the relevant code from that line? – Swifty Sep 18 '16 at 19:22
  • And while you're at it if you can please include the complete crash report and relevant code for line number 2 and 1 from the crash report, so I can see what's going on to find out what's causing the crash. – Swifty Sep 18 '16 at 19:26
  • You can also set break points to find out the exact line that is causing crash – Swifty Sep 18 '16 at 19:36
  • All this crash is happening in the Smartphone of one of the testers, not in others... I decided to install XCode on his mac, connect that iPhone and see directly what is happening (via teamviewer cause' he is in a different country right now)... I will post here the solution... I really think the crash report from HockeyApp have some error, or at least is not pointing to the correct line.. – Adrián Rivero Sep 20 '16 at 08:45