Warum diese Linie NSNotificationCenter.defaultCenter().postNotificationName(...) wirft SIGABRT
Spiele ich mit NSNotificationCenter in swift. Das ist mein code in main.swift
import-Stiftung
class T: NSObject {
func someAction(notification: NSNotification) {
println(notification.userInfo)
}
}
var dataDict = Dictionary<String, String>()
dataDict["test"] = "test"
dataDict["test1"] = "test1"
var t = T();
NSNotificationCenter.defaultCenter().addObserver(t, selector:"someAction", name: "someAction", object:nil)
NSNotificationCenter.defaultCenter().postNotificationName("someAction", object:nil, userInfo:dataDict)
let runloop = NSRunLoop.currentRunLoop();
runloop.run();
println("Done");
In der Zeile postNotification
bekam ich eine Ausnahme:
Hier einige stacktrace:
2014-07-24 08:58:59.959 testswiftcli2[2171:303] -[_TtC13testswiftcli21T someAction]: unrecognized selector sent to instance 0x1005005a0
2014-07-24 08:58:59.961 testswiftcli2[2171:303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_TtC13testswiftcli21T someAction]: unrecognized selector sent to instance 0x1005005a0'
Wenn ich versuchte, Sie zu inspizieren das Beispiel, ich habe dieses:
(lldb) po 0x1005005a0
4300211616
Wie es scheint, die variable ist schon Weg out of scope. Ist es eine richtige Schlussfolgerung?
Was ist das problem mit dem code oben?
Du musst angemeldet sein, um einen Kommentar abzugeben.
Den Selektor sollte
someAction:
stattsomeAction
weil es ein argument.