1

当我将 UserDefaults 的数据放在主应用程序中并一次调用扩展函数时是否有可能?

我在这里找到了另一种方式
如何在今日扩展中发送和接收数据

但它不起作用,以下是我的代码

主应用

@IBOutlet weak var nextButton: UIButton! {
    didSet {
        nextButton.addTarget(self, action: #selector(selectNextButton), for: UIControlEvents.touchUpInside)

    }
}

func selectNextButton() {
    NotificationCenter.default.post(name: NSNotification.Name(rawValue: "SpecialKey"), object: nil, userInfo: ["MyData": 10])
}

今天延长

override func viewDidLoad() {
    super.viewDidLoad()
    NotificationCenter.default.addObserver(self, selector: #selector(dataReceived(notification:)), name: NSNotification.Name(rawValue: "SpecialKey"), object: nil)       
}

func dataReceived(notification: NSNotification) {
    print("Received Data")
}
4

0 回答 0