How to detect window resizing in Mac Catalyst? - swift

How can I a get a notification when user resize the window while:
NotificationCenter.default.addObserver(self, selector: #selector(function), name: NSWindowDidResizeNotification, object: nil)
is unavailable in Mac Catalyst

Just like in iOS. Use windowScene(_:didUpdate:interfaceOrientation:traitCollection:) in your window scene delegate, or implement viewWillTransition(to:with:) in your view controllers.

Related

how to reload NSTableView data from a different ViewController

I'm working on a simple notes app for macOS. I have a home page which is has a NSTableView that displays all your notes, when you click the new note button a new View appears where you can create a new note. Once you click the note it adds the new note to the database and should reload the table view data, but I need to stop the current run and run the program again to see the changes.
I used this post to achieve the same effect on iOS but it seems to not work on MacOS
So how do I adapt:
override func viewDidLoad() {
super.viewDidLoad
NotificationCenter.default.addObserver(self, selector: #selector(loadList), name: NSNotification.Name(rawValue: "load"), object: nil)
}
In the home page VC
and the line:
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "load"), object: nil)
Inside of the saveNewNote IBAction to work in macOS? also are you even able to use the NotificationCenter in macOS apps or is it only on iOS?
NSNotificationCenter is part of Foundation framework, so it's definitely available on macOS.
You should be able to use it the same way you've been using it on iOS.
If you have an IBAction called saveNewNote, inside that method you can posy the notification the way you wrote.
In the view controller which owns the table, add the observer like you wrote, and reload the table...
If it doesn't work, we might need some code example of how you set it up on the Mac app the better understand what isn't working.

How to implement android's onResume() function in swift?

I'm using an observer like below to run code when the app comes back to the app from the background
However, if the app is run after a day or so, the observer does not run.
Is there a way to make the observer run even if the app runs after a day or two, or to have the same effect as onResume() in android?
NotificationCenter.default.addObserver(self, selector: #selector(enterForeground), name: UIApplication.didBecomeActiveNotification, object: nil)

Detect UIViewController changed in Swift

For analytics purposes, I would like to detect whenever the top UIViewController is modified.
I don't want to use inheritance, but rather delegate some event that I can use.
I see that Firebase have some type of mechanism for that but I couldn't figure how exactly.
Something like the following will be great:
NotificationCenter.default.addObserver(self, selector: #selector(topViewModified), name: .TopViewModified, object: nil)
Thanks.

UIKeyboardWillChangeFrameNotification swift implementation

For a long while now, I've been looking for a Swift implementation that utilizes UIKeyboardWillChangeFrameNotification so far I haven't come across anything. I'm trying to get this working so that I can handle the keyboard show and hide in one method as stated in the documentation here and here written in objective-c.
and replace these:
// Register your Notification, To know When Keyboard appears.
NotificationCenter.default.addObserver(self, selector: #selector(myKeyboardWillShowMethod), name: .UIKeyboardWillShow, object: nil)
// Register your Notification, To know When Keyboard hides.
NotificationCenter.default.addObserver(self, selector: #selector(myKeyboardWillHideMethod), name: .UIKeyboardWillHide, object: nil)

Swift - How do you tell when a NSScrollView starts to scroll?

Is there a way in Swift to tell when a NSScrollView has begun scrolling.
You can use an observer that listens to the NSScrollViewWillStartLiveScrollNotification [1]
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(YourClass.YourFunctionName), name: NSScrollViewWillStartLiveScrollNotification, object: nil)
Just place your function inside the #Selector()