nsnotifications

How to pass object with NSNotificationCenter

╄→尐↘猪︶ㄣ 提交于 2019-11-26 08:44:55
问题 I am trying to pass an object from my app delegate to a notification receiver in another class. I want to pass integer messageTotal . Right now I have: In Receiver: - (void) receiveTestNotification:(NSNotification *) notification { if ([[notification name] isEqualToString:@\"TestNotification\"]) NSLog (@\"Successfully received the test notification!\"); } - (void)viewDidLoad { [super viewDidLoad]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismissSheet) name

NSNotificationCenter vs delegation( using protocols )?

柔情痞子 提交于 2019-11-26 06:59:46
问题 What are the pros and cons of each of them? Where should I use them specifically? 回答1: The rule of thumb here is how many clients would like to be notified of an event. If it's mainly one object (e.g. to dismiss a view or to act upon a button clicked, or to react to a failed download) then you should use the delegate model. If the event you emit may be of an interest to many objects at once (e.g. screen rotated, memory usage, user login/logout), then you should use the NSNotificationCenter .

How to pass data using NotificationCenter in swift 3.0 and NSNotificationCenter in swift 2.0?

泪湿孤枕 提交于 2019-11-26 03:49:13
问题 I\'m implementing socket.io in my swift ios app. Currently on several panels I\'m listening to the server and wait for incoming messages. I\'m doing so by calling the getChatMessage function in each panel: func getChatMessage(){ SocketIOManager.sharedInstance.getChatMessage { (messageInfo) -> Void in dispatch_async(dispatch_get_main_queue(), { () -> Void in //do sth depending on which panel user is }) } } However I noticed it\'s a wrong approach and I need to change it - now I want to start