It is more a problem of design here. Your function getContacts should not update the text field directly. It should return the contact string, and the view controller should call this method to get the string and update the text field. class ContactData: NSObject { func getContacts() -> String {...

I think you need to have a custom server that handles the logic of booking and sending push notifications. If your concern is only about sending notifications directly between apps without a custom server, you can use some messaging services like PubNub.

If your method doesn't have any parameter then you can call it this way: NSNotificationCenter.defaultCenter().addObserver(self, selector: "accessoryDidConnectNotify", name: EAAccessoryDidConnectNotification, object: nil) by using "accessoryDidConnectNotify". So that you can use that method like: func accessoryDidConnectNotify(){ // works fine (with no arguments) //Your code } But if your method have parameters then...

NSNotificationCenter doesn't retain it's targets, this leads to errors where it will send a message to an object that has been deallocated. It sounds like you are not removing the object from NSNotificationCenter on deinit and another object (NSArray in this case) just happens to be occupying that space and...

The solution to the second part of the question was to raise the scope of the object containing the callback code. I raised it to the level of the containing ViewController. This seems to work. I still can't figure out how to raise the Notification (i.e. execute the call back)...

Sorry for my typo, I am removing observer in the source ViewController where I am triggering the NSNotification, I should remove it from second ViewController where its being used. in ViewController1: [[NSNotificationCenter defaultCenter] postNotificationName:@"textUpdateNotification" object: nil ]; in ViewController2: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveNotification:) name:@"textUpdateNotification" object:nil]; -(void)receiveNotification:(NSNotification *)notificaton { .... .......

If you are receiving the remote notification, I suggest you to just handle the notification at AppDelegate.swift at method: func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]){ // Here you can define view controller and manage it. println("Received: \(userInfo)") // Make root view controller first as per your need as...

You're choosing one object from the set when using url.anyObject(). Instead you need to get all objects from the set and then iterate through the array. The following code should help you: func assetChange(notification: NSNotification) { if var info:NSDictionary = notification.userInfo { var url:NSSet = info.objectForKey(ALAssetLibraryUpdatedAssetsKey) as NSSet var urls:...

In general, for any notification, stop observing when you no longer care about the notification. One case where you don't care any more is when the object that is observing the notification gets deallocated. What that second article is telling you is that removeObserver: is often not the best choice....

You need to remove GameScene as an observer from NSNotificationCenter when the object is deinitialized. The code below should fix your issue. deinit { NSNotificationCenter.defaultCenter().removeObserver(self) } ...

Private methods are just that: private. They still exist, they're just kept secret from the outside world. There's nothing built in to Objective-C to check where a method is being called from and complain at runtime; that compile-time warning about an undeclared selector is exactly the failure of Class B...

It might be a solution not reloading cells at all. Just make the cells listen to an update notification and change their label accordingly. I assume you subclass UITableViewCell and give the cell a storedDate property. You will set that property when preparing the cell. The timer will just fire...

While the notification center was present, the app was never in the background, so it does not come to the foreground when the notification center is dismissed - and so there is no UIApplicationWillEnterForegroundNotification. The app is activated, not foregrounded. Watch for UIApplicationDidBecomeActiveNotification instead.

You have reached a dead-end. There is no api or event to support display of TODAY notification view. It is left for users 'will', when he wish to navigate to TODAY view, as otherwise it can easily become a inconvenience.

As has been pointed out, for table and collection views, the best bet is NSFetchedResultsControllerDelegate. Another mechanism is to register for this (or your custom) notification NSNotificationCenter, e.g. for the original notification: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateUI:) name:NSManagedObjectContextDidChangeNotification object:nil]; Best do this in viewDidAppear. Don't forget to remove the observer in...

That's because the selector you're using doesn't specify that the method it should notify has a parameter. Try this: NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWasShown:"), name: UIKeyboardDidShowNotification, object: nil) (Note the : in the selector.) See Objective-C: Calling selectors with multiple arguments (this still applies in Swift)....

Found it: the problem was that the controller kept "listening" even when there was a failed message being sent because of the [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(logInAttemptComplete:) name:@"logInNotification" object:nil]; being inside the function of pressing the log in button. All I had to do was add the [[NSNotificationCenter defaultCenter] removeObserver:self name:@"logInNotification"...

The best way to run code at the deallocation of an object for which you can't override dealloc is by using associated objects. The object that you associate to will release its strongly-held associated objects when it deallocates. As long as that is the only owner, the associated object's dealloc...

If the indicator stops after a few seconds, then make sure that the code that stops the indicator runs on the main thread. if it runs on a different thread then use this snippet: dispatch_async(dispatch_get_main_queue(), ^{ self.activityIndicator.hidden = YES; [self.activityIndicator stopAnimating]; [self.activityIndicator removeFromSuperview]; }) ...

If this is a view-based table view which (perhaps implicitly) loads its views from NIBs, then its awakeFromNib method will get called each time the NIB is loaded. From here: Note: Calling makeViewWithIdentifier:owner: causes awakeFromNib to be called multiple times in your app. This is because makeViewWithIdentifier:owner: loads a NIB...

Even if there are some official APIs to do this, I strongly suggest you to NOT use them, cause they're leaked. You can use FXNotifications from Nick Lockwood, which provides the feature you want: use a block as notification listener. Add the .h & .m files inside your project and...

The Core Plot hosting view removes itself as an observer of all notifications whenever you set the hosted graph or the collapsesLayers property. Please post a bug report on the issue tracker if you'd like us to fix it. In the meantime, add your observers after you set up the...

Since the for loop is running the main thread this thread gets blocked until the for look is completed. Since the main threat is also the UI thread your UI updated aren't done until the loop is finished. You should run the loop on a background thread an the UI...

First of all: User events (as a mouse down) are always delivered on the main thread. Therefore you do not need the -performSelectorOnMainThread:…. To your Q: Likely you misunderstood the object parameter. Why do you set it to nil when posting a notification and set it to self for adding...

The problem occurs because you are sending the message before the second view controller is registered. NSNotificationCenter doesn't support sticky notifications - in other words, the message won't be cached. If no-one is listening at the very moment the notification is sent, it's just gone. The easiest fix is to...

You must create a Reachability object before you can receive notifications from it. Also, be sure to call the startNotifier() method on the Reachability object you create. This would be an example of how to do so inside of your application delegate: class AppDelegate: UIResponder, UIApplicationDelegate { private var reachability:Reachability!;...

Another option is to use two great libraries for this. BSKeyboardControls for the tabbing and TPKeyboardAvoiding for moving the view. If you just want to send the notification my guess is that [[NSNotificationCenter defaultCenter] postNotificationName: UIKeyboardDidShowNotification object:self] should work just fine....

You can use the UITextField/View delegate to get notified when a text field begins editing. E.g. - (void)textFielDidBeginEditing:(UITextField *)textField { // Push screen up } It's worth noting that if the user has a external keyboard attached the on screen keyboard will not show but the screen will still be...

You are registering the TableView only for notifications sent by itself. It should be.. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleSuccessSocket) name:kNotificationServiceStartSuccessful object:nil]; ...

When you use the 'blocks' based approach to observing notifications then self isn't in fact the observer. The function returns an object which acts as the observer: func addObserverForName(_ name: String?, object obj: AnyObject?, queue queue: NSOperationQueue?, usingBlock block: (NSNotification!) -> Void) -> NSObjectProtocol You need to keep a reference...

Echoing @0x7fffffff's comment, if you register an observation, you almost always want to have: - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } There is (usually) little cost to removing yourself from the notification center, and it does not care if you are an observer or not, so this is good insurance...

The problem was not with the notifications, it was the panel which was causing problems: I was opening the panel in my main window controller: [[self window] beginSheet:self.panelClass.panel completionHandler:nil]; And the closing action of the panel was written in the Panel window controller. Because of this reason no NSBeginAlertSheet was...

If you have the productCode variable at the time of registering for this notification, then you could use a different notification observing method. let productCode = "A string" NSNotificationCenter.defaultCenter().addObserverForName(UIApplicationDidBecomeActiveNotification, object: nil, queue: NSOperationQueue.mainQueue()) { (notification) -> Void in self.dataMain(productCode) } ...

This line: [[NSNotificationCenter defaultCenter] removeObserver:@"downloadNotification"]; should be: [[NSNotificationCenter defaultCenter] removeObserver:self]; because the parameter is the object to remove as an observer, not the name of the notification. This error will result in the deallocated view not being removed as an observer so you will get a crash the next time...

First off, creating new background queue every time that function runs is probably not what you want. There are limits how many queues you can have, and this is right way to reach that limit quickly and crash. Use something like this: dispatch_async(dispatch_get_global_queue(QOS_CLASS_UTILITY, 0), block); Secondly, there is nothing wrong...

Try posting your notification when you are confident your "ViewController" object has instantiated and/or come into view. E.G. why not try it out by putting it into an "IBAction" method fired by some UIButton? The observing view controller may or may not (more likely not in your case) be existing...

You can initialize global variables with literals or nil. If you do not so, they are implicitly initialized with nil. If you do want to initialize them with another value, you have to do that in a piece of code that is executed at the very beginning, for example in...