nsnotificationcenter

Type 'NSNotification.Name' has no member 'UITextField'

馋奶兔 提交于 2020-08-01 01:09:43
问题 With Swift 4.2, getting following error, that was working fine with Swift 4. Type 'NSNotification.Name' has no member 'UITextField' Here is my error code. NotificationCenter.default.addObserver(forName: NSNotification.Name.UITextField.textDidChangeNotification, object: textField, queue: OperationQueue.main) { (notification) in loginAction.isEnabled = textField.text != "" } Full Code: @IBAction func alertWithLogin(){ let alertController = UIAlertController(title: "Please Enter Credential",

Type 'NSNotification.Name' has no member 'UITextField'

北城余情 提交于 2020-08-01 01:09:10
问题 With Swift 4.2, getting following error, that was working fine with Swift 4. Type 'NSNotification.Name' has no member 'UITextField' Here is my error code. NotificationCenter.default.addObserver(forName: NSNotification.Name.UITextField.textDidChangeNotification, object: textField, queue: OperationQueue.main) { (notification) in loginAction.isEnabled = textField.text != "" } Full Code: @IBAction func alertWithLogin(){ let alertController = UIAlertController(title: "Please Enter Credential",

NSNotificationCenter addobserver not calling the selector method in SWIFT

筅森魡賤 提交于 2020-06-28 20:24:14
问题 I know that this question has been asked quite many times but I am damn tired of searching for this error but couldn't make it. I have a scenario in which I am moving from one viewController to another i.e (VC1->VC2). I am using NSNotificationCenter to pass some data to the other VC. VC1 - @IBAction func sendNotfctn(sender: AnyObject) { NSNotificationCenter.defaultCenter().postNotificationName("MY NOTIFICATION", object: self) performSegueWithIdentifier("Go", sender: self)//Here I move to VC2.

How to communicate between iOS App Containing Extension and Extension (not Host App)

空扰寡人 提交于 2020-06-24 01:54:47
问题 TLDR: Is it possible to send realtime messages or notifications between iOS App and it's Extension? I'm writing an iOS App with an extension that are part of the same App Group and share the same CoreData (SQLite database). I can read and write to the database using CoreData from the App and from the extension, they both share the same content. My Question is: Is it possible to send messages or notifications between the App and the extension to notify the other to update if necessary? I tried

NSManagedObject's hasChanges is true while changedValues is empty

我的梦境 提交于 2020-06-10 02:55:25
问题 I am trying to observe individual NSManagedObject changes on NSManagedObjectContextWillSaveNotification : - (void)managedObjectContextWillSave:(NSNotification *)notification { for (NSManagedObject * object in self.mutableObservedManagedObjects) { if (object.hasChanges) { [self managedObjectWasUpdated:object]; } } } The problem is that hasChanges is true while object.changedValues is empty, thus wrongly (?) triggering managedObjectWasUpdated: . I'm trying to understand why this is the case and

NSManagedObject's hasChanges is true while changedValues is empty

流过昼夜 提交于 2020-06-10 02:53:23
问题 I am trying to observe individual NSManagedObject changes on NSManagedObjectContextWillSaveNotification : - (void)managedObjectContextWillSave:(NSNotification *)notification { for (NSManagedObject * object in self.mutableObservedManagedObjects) { if (object.hasChanges) { [self managedObjectWasUpdated:object]; } } } The problem is that hasChanges is true while object.changedValues is empty, thus wrongly (?) triggering managedObjectWasUpdated: . I'm trying to understand why this is the case and

Swift NotificationCenter remove observer quickest way

那年仲夏 提交于 2020-04-11 15:23:54
问题 I am adding a number of observers in my viewController -- applicationWillResignActive , applicationDidEnterBackground , and many others. I want to remove self as observer to all registered notifications in one line. My question is whether the following line is enough to do that, or are there issues with this code? deinit { NotificationCenter.default.removeObserver(self) } 回答1: @Sh_Khan is right: NotificationCenter.default.removeObserver(self) You can get even further, as mentioned in the

Swift NotificationCenter remove observer quickest way

天涯浪子 提交于 2020-04-11 15:23:43
问题 I am adding a number of observers in my viewController -- applicationWillResignActive , applicationDidEnterBackground , and many others. I want to remove self as observer to all registered notifications in one line. My question is whether the following line is enough to do that, or are there issues with this code? deinit { NotificationCenter.default.removeObserver(self) } 回答1: @Sh_Khan is right: NotificationCenter.default.removeObserver(self) You can get even further, as mentioned in the

Swift NotificationCenter remove observer quickest way

余生长醉 提交于 2020-04-11 15:22:53
问题 I am adding a number of observers in my viewController -- applicationWillResignActive , applicationDidEnterBackground , and many others. I want to remove self as observer to all registered notifications in one line. My question is whether the following line is enough to do that, or are there issues with this code? deinit { NotificationCenter.default.removeObserver(self) } 回答1: @Sh_Khan is right: NotificationCenter.default.removeObserver(self) You can get even further, as mentioned in the

How to determine whether the app is opened from NotificationCenter (Local Notification) or the app icon when app is killed

本秂侑毒 提交于 2020-03-05 09:34:06
问题 My App receives a local notification Not a remote Notification. How can I know if the app is opened by pressing the notification and not the app icon when the app is killed( Not running in background or foreground). Previosuly, I used the following method func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { if ((launchOptions?[UIApplication.LaunchOptionsKey.loaclNotification] != nil)) { print("here") } }