Global variables and function names have external linkage. These are accessed from other files by declaring them with the keyword extern.
Somewhere in your header, you would declare a global variable like this: extern int GlobalInt; The extern part tells the compiler that this is just a declaration that an object of type int identified by GlobalInt exists.
From the official Swift programming guide: Global variables are variables that are defined outside of any function, method, closure, or type context. Global constants and variables are always computed lazily. You can define it in any file and can access it in current module anywhere.
I am working on a project where I must extend an objective-c application with some Swift code. So I need to access the Swift code from an .m file.
I imported the generated Swift.h file and now I have access to the methods, but not to the global variables.
Is it possible to do that?
Thanks!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With