Pass object with NSNotificationCenter to other view

后端 未结 2 1605
栀梦
栀梦 2021-01-04 18:55

I am trying to pass an object from my main view class to other notification receiver in another class.

I want to pass an object named country, that loads all the cit

2条回答
  •  青春惊慌失措
    2021-01-04 19:00

    For Swift You can pass dictionary with using the below code

    NSNotificationCenter.defaultCenter().postNotificationName(aName: String, object anObject: AnyObject?, userInfo aUserInfo: [NSObject : AnyObject]?)
    

    for example

    NSNotificationCenter.defaultCenter().postNotificationName("OrderCancelled", object: nil, userInfo: ["success":true])
    

    And read this dictionary from

     func updated(notification: NSNotification){
    
             notification.userInfo?["success"] as! Bool 
        }
    

提交回复
热议问题