为什么这行NSNotificationCenter.defaultCenter().postNotificationName(...)抛出SIGABRT

Ant*_*ong 2 nsnotificationcenter swift xcode6

我在swift中玩NSNotificationCenter.这是我的代码main.swift

进口基金会

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");
Run Code Online (Sandbox Code Playgroud)

在线postNotification,我有一个例外:

在此输入图像描述

这是一些堆栈跟踪:

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'
Run Code Online (Sandbox Code Playgroud)

当我试图检查实例时,我得到了这个:

(lldb) po 0x1005005a0
4300211616
Run Code Online (Sandbox Code Playgroud)

似乎变量已经超出了范围.这是一个正确的结论吗?

上面的代码有什么问题?

jtb*_*des 6

选择应该是someAction:,而不是someAction因为它有一个参数.