Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function signature specialization crash in swift

Tags:

ios

swift

I am getting crash reports from our users but I didn't understand the crash report.

It says:

Ribony: function signature specialization <Arg[0] = Owned To Guaranteed and Exploded, Arg[1] = Owned To Guaranteed and Exploded, Arg[2] = Owned To Guaranteed and Exploded, Arg[3] = Exploded, Arg[4] = Owned To Guaranteed> of Ribony.ChatManager.sendMessage (Ribony.ChatManager)(Swift.String, to : Swift.String, anonClosed : Swift.String, toWeb : Swift.Int) -> () + 3608

enter image description here

I am using swift. What is this report? My sendMessage method:

func sendMessage(message: String,to: String,anonClosed: String,toWeb: Int) {
        NSNotificationCenter.defaultCenter().postNotificationName(mySpecialNotificationKey, object: self,userInfo:["message":message])
        var sender=""
        var token=""
        var toSubstr=""
        if count(to) >= 5 {
            let rangeOfTo = Range(start: to.startIndex,
            end: advance(to.startIndex, 5))
            toSubstr = to.substringWithRange(rangeOfTo)
        }else{
            toSubstr=to
        }
        socket.emit("sendMessage","ok")
}

How can I resolve it?

like image 308
Tolgay Toklar Avatar asked Sep 18 '15 15:09

Tolgay Toklar


2 Answers

You need to look at what the actual exception is. The most common is "unexpectedly found nil while unwrapping an Optional Value" which would suggest that you're passing a String! to this method that was really nil. But you need to start by looking at the exception message, not just the crash stack.

like image 54
Rob Napier Avatar answered Nov 20 '22 17:11

Rob Napier


Taken from here: https://forums.developer.apple.com/thread/6078

The message seems to correlate with passing a nil object to a swift function that expects non-nil object.

So change your function signature to: func sendMessage(message: String?,to: String?,anonClosed: String?,toWeb: Int?) or make sure it gets called with non-nil objects from Objective C

like image 1
amleszk Avatar answered Nov 20 '22 18:11

amleszk