What is parameter `object` in NSNotification addObserver:?

前端 未结 3 1584
温柔的废话
温柔的废话 2020-12-29 22:31

One of my class named Message.m is posting a notification with an object sentObject as below

NSDictionary *sentObject = [NSDictionary dictionary         


        
3条回答
  •  旧时难觅i
    2020-12-29 22:58

    You can use it to pass any object with the notification. The receiver of the notification will then be able to access that object. For example, you could implement dataReloaded like this:

    - (void)dataReloaded:(NSNotification *)notification {
    
        NSLog(@"%@", notification.object); // this will log the object you passed in addObserver:selector:name:object:
    
    }
    

    It can be useful when you want to pass on data with your notification, so that the receiver of a notification can use that data too.

提交回复
热议问题