Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to access Swift global variables from an objective-c file? [duplicate]

Tags:

People also ask

Can global variables be accessed in another file?

Global variables and function names have external linkage. These are accessed from other files by declaring them with the keyword extern.

How do I declare a global variable in Objective C?

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.

Does Swift have global variables?

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!


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!