You want to use a property
so try this
MyClass.h
@interface MyClass : NSObject
// Because the property is here it is public so instances
// of this class can also access it.
@property (assign) int myInt;
@end
MyClass.m
#import "MyClass.h"
// If you wish to make the property private then remove the property from above and add
// Only do this if you want it to be private to the implementation and not public
@interface MyClass()
@property (assign) int myInt;
@end
@implementation MyClass
// The synthesize is done automatically so no need to do it yourself
- (id)init
{
self = [super init];
if(self) {
// Set the initial value of myInt to 1
self.myInt = 1;
}
return self;
}
- (void)methodOne
{
// Reassign to 5
[self setMyInt:5];
}
- (void)methodTwo
{
// NSLog the value of the myInt
NSLog(@"MyInt is equal to: %d", [self myInt]);
}
@end
There is quite a bit of Apple documentation on properties in objective-c, so here they are:
Naming Properties and Data Types
Encapsulating Data
Declared property
Defining Classes
Enjoy a good read.