Created
June 14, 2018 02:41
-
-
Save acalism/ebb69a3d34ec3828c8c5875a746a02c2 to your computer and use it in GitHub Desktop.
Difference between ivar and global var
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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