I just found 5 crash reports inside the xcode organizer. When I open them I get this stacktrace (marked area is the name of my app):
This error occurs on iOS8.4 as well as on iOS9, and on iPhone 5 and iPhone 6 devices likewise.
It is hard for me to track down because I cannot reproduce it neither on iPhone5(8.4) nor on iPhone6(9.0.1).
1./2. somewhere here:
override func onButtonTableViewCellClick(button: BfPaperButton) {}
3.
var button: BfPaperButton = BfPaperButton.newAutoLayoutView()
func onClick() {
delegate?.onButtonTableViewCellClick(button) // 3
}
I use swift 2, xcode 7 and iOS9. Help me to understand the error. What does the first line with the red image mean? Why has this error something to do with Swift.String
at all??
I found this thread: https://forums.developer.apple.com/thread/6078 where I extracted this information:
One case I've seen of this kind of crash is when an Obj-C-based object calls a delegate method that's Swift-based, and a parameter value is nil but the Swift method signature isn't an optional type. In the case I saw, it was an error in the bridged delegate method signature — it was actually supposed to be optional. It could be something similar in your case (the Swift definition doesn't allow for an optional when it should), or it could be a bug in the Obj-C code (producing nil when it shouldn't).
I use a obj-c lib called BfPaperButton which creates a Button that looks like in android material design. Maybe the error is related to this library?
Log:
View image: https://i.stack.imgur.com/5aQ8m.png
I have two string extensions. One for length and one for substring:
extension String {
var length: Int { return self.characters.count }
subscript (i: Int) -> String {
return String(Array(self.characters)[i])
}
subscript (r: Range<Int>) -> String {
let start = startIndex.advancedBy(r.startIndex)
let end = startIndex.advancedBy(r.endIndex)
return substringWithRange(Range(start: start, end: end))
}
}
Line 188 is:
NSUUID().UUIDString[0...4]
which uses substring extension. Maybe the error is here?
override func onButtonTableViewCellClick(button: UIButton) {
if let title = button.titleLabel?.text {
if title == "Send code" {
tmpPhoneNumber = ""
var tmp = phoneNumber
if tmp.length > 1 {
if tmp[0] == "0" {
tmp = tmp[1...tmp.characters.count - 1]
}
tmpPhoneNumber = "0049" + tmp
phoneNumberWithCode = tmpPhoneNumber
sendAlert(tmp)
} else {
PfToast.showError("Please enter your phone number.")
}
} else if title == "Finish" {
if let cell: InputTableViewCell = tableView.cellForRowAtIndexPath(NSIndexPath(forRow: 0, inSection: 2)) as? InputTableViewCell {
if isLicenceValid(cell.inputField.inputField.text!) {
createCustomer(cell.inputField.inputField.text!)
} else {
PfToast.showError("Please enter correct licence plate.")
}
}
}
}
}