I want to create an OS-X application with swift, but I don't know how to pass the value from ViewController to AppDelegate.
I would like to receive a value in AppDelegate applicationWillTermination (aNotification:NSNotification).
I would like to declare this class variable in AppDelegate Class in the form of var Flag:Int?, but I don't know how to have ViewController set the value.
Thank you for your cooperation.
swift macos
For iOS, UIApplication.sharedApplication().delegate
allows you to see an instance of AppDelegate
, which is the same for OS X.
NSApplication.sharedApplication().delegate as?AppDelegate
It is now available.
I'd like to use this class variable by declaring it in the form of var Flag:Int? in the AppDelegate Class.
Swift, like Objective-C, had the instance variable but no class variable...
One technique of Swift is to keep variables as optional as possible.
Following Swift's naming convention, variables start with lowercase letters.
var flag: Int=0
If you give an initial value, you can make it non-Optionsal and use it without ! or ?.
Gift:
AppDelegate
is in the Responder Chain path, so Action with the target
set to nil
can be received by Action methods written in the AppDelegate
class if no Action method is written in the middle of the path.
© 2024 OneMinuteCode. All rights reserved.