Skip to content

Instantly share code, notes, and snippets.

@acalism
Created June 14, 2018 02:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acalism/ebb69a3d34ec3828c8c5875a746a02c2 to your computer and use it in GitHub Desktop.
Save acalism/ebb69a3d34ec3828c8c5875a746a02c2 to your computer and use it in GitHub Desktop.
Difference between ivar and global var
@implementation MyClass {
// It is an ivar, or called member variable
// Can NOT be initialized when defined.
// Can be accessed with `self->_i`
int _i;
}
int i = 9; // Global variable, and can be initialized when defined.
@end
// Another file
extern int i;
NSLog(@"%i", i);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment