////////////////////////////// //ex3 demonstrates: // //instance variables // // I would like to keep this Jump Start simple without adding extra syntax but it is worth noting that there are three access modifiers: @public, @private and @protected // //Objective-c does not support class variables only instance level variables (you can declare a static variable outside @interface, though) ////////////////////////////// #include <Foundation/Foundation.h> @interface MyClass: NSObject { int myInteger; // instance variables go between the curly braces in the @interface section. } -(void) setInteger: (int) n; -(int) getInteger; @end @implementation MyClass -(void) setInteger: (int) n; { myInteger = n; } -(int) getInteger { return myInteger; } @end int main(void) { MyClass *myInstance = [MyClass new]; [myInstance setInteger: 123]; int AnInteger; AnInteger= [myInstance getInteger]; printf("The integer is: %i \n\r", AnInteger); return 0; } |