I want to do:
#include "MyClass.h" MyClass *obj = new MyClass();
I tried it in main.mm, inside main(), in my appDelegate.mm and inside application:didFinishLaunchingWithOptions. But none of those seem to work.
Otherwise I have to pass the pointer into every object. This involves another interface, more method calls and more #includes.
Thank you
Yes, it’s perfectly possible.
Just remember to use
externkeyword in the translation units you are going to use the global variable.For example, in you main.m file:
And where you are going to use it, in other_file.m put: