Swift "Specialized" Crash Swift "Specialized" Crash swift swift

Swift "Specialized" Crash


You will need to create the User object for the case for when indexPath.section == 2 as you have 3 sections. You will need to ensure the 'user' object is properly initialised in this code block (refer to inline comment in the code)

    var user: TetherUser!    if searching {        user = searchedUsers[indexPath.row]    } else {        if indexPath.section == 0 {            user = users[indexPath.row]            cell.actionButton.friendIsContact = false        } else if indexPath.section == 1 {            user = contactsWithApp[indexPath.row]            cell.actionButton.friendIsContact = true        } else if indexPath.section == 2 {         // Add code here to ensure user has proper value.        }    }


I have this "specialized" error also. The crashes only happen on iOS 8.0 and 8.1. This is a part of my stack trace.

Crashed: com.apple.main-thread0  Viki                           0x10027bb28 specialized LoginFlowSocialButton.traitCollectionDidChange(UITraitCollection?) -> () + 42972434321  Viki                           0x10027ad30 @objc LoginFlowSocialButton.traitCollectionDidChange(UITraitCollection?) -> () (LoginFlowButton.swift)2  UIKit                          0x18a696cd4 -[UIView _processTraitsDidChangeRecursively:forceNotification:] + 1243  UIKit                          0x18a3d05f4 __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 3484  UIKit                          0x18a3d0408 -[UIView(Hierarchy) _postMovedFromSuperview:] + 4845  UIKit                          0x18a3dbea4 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 17246  UIKit                          0x18a694f34 -[UIView initWithCoder:] + 756...

I try downloading one of iOS simulators with those versions and test again. Turns out the crash is from using a forced unwrapped var but found nil in traitCollectionDidChange function.

So the lesson here is just that the specialized function in the error message may not point to the exact problem. You can try look more into that function and see what went wrong in there.

Hope that helps. :)