今天扩展与 NSNotificationCenter 崩溃

Today extension crashing with NSNotificationCenter

我正在创建 grows/shrinks 的今日扩展以节省 space。在通知中心,但我在使用 NSNotificationCenter 时遇到了问题。如果我调用 visibility() 函数,视图会正常收缩和增长,但如果我尝试发布通知,扩展会失败并尝试重新加载(至少第一次,第二次扩展只是说 "Unable to load".这是为什么?

var NSNotificationDidChoose = "NSNotificationDidChoose"    
@IBOutlet var tableView: UITableView!    
@IBOutlet var activityIndicator: UIActivityIndicatorView!    
@IBAction func shrink(sender: AnyObject) {
    //visibility(["bool":false])works fine here
    NSNotificationCenter.defaultCenter().postNotificationName(NSNotificationDidChoose, object: nil, userInfo: ["bool":false])
        //Crashes and the extension reloads


}
@IBAction func unshrink(sender: AnyObject) {
    //visibility(["bool":true]) works fine here
    NSNotificationCenter.defaultCenter().postNotificationName(NSNotificationDidChoose, object: nil, userInfo: ["bool":true]) 
//Crashes and the extension reloads
}
@IBOutlet var buttonview: UIView!

func visibility(boole:[NSObject:AnyObject]) {
    var bool = boole["bool"] as Bool
    println(bool)
    tableView.hidden = !bool
    activityIndicator.hidden = !bool
    if bool {
        self.preferredContentSize = CGSize(width: 350, height: 420)
    } else {
        self.preferredContentSize = CGSize(width: 350, height: buttonview.frame.height+25)
    }
}
override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(true)
    NSNotificationCenter.defaultCenter().addObserver(self, selector: "visibility:", name: NSNotificationDidChoose, object: nil)
}

通知方法的参数是NSNotification。试试这个。

func visibility(notif: NSNotification) {
    let boole = notif.userInfo!
    var bool = boole["bool"] as Bool
    ....
}