Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variable Declaration in Objective-C - interface vs implementation [duplicate]

Whats the difference between these two:

@interface MyClass ()
{
    BOOL newUser;
}

Or

@implementation MyClass
{
BOOL newUser;
}

@end
like image 765
kamran619 Avatar asked Mar 10 '26 16:03

kamran619


1 Answers

variables declared in your interface, as in 1., are visible in other classes that instantiate objects of MyClass. The variable declared in 2. will only be visible inside of MyClass. Here is something you should read: http://developer.apple.com/library/ios/#referencelibrary/GettingStarted/Learning_Objective-C_A_Primer/

EDIT: @JoshCaswell is right. 1. is an anonymous category. Its varaibles will be seen depending on where the interface is declared. a better link to read about this is: http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/ProgrammingWithObjectiveC/CustomizingExistingClasses/CustomizingExistingClasses.html

like image 72
katzenhut Avatar answered Mar 12 '26 06:03

katzenhut



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!