This is the first program (that is not doing much basically), and I know usually you define classes in separate files, but just wanted to see if I got the syntax right, and the concept of using objects from the first chapter of the book.
This is the code:
#import <Foundation/Foundation.h>
//interface section
@interface Watch: NSObject
-(void) setHours: (int) h;
-(void) setMinutes: (int) m;
-(int) getHours;
-(int) getMinutes;
-(void) printTime;
@end
//implemetation section
@implementation Watch
{
int hours;
int minuts;
}
- (void) setHours: (int) h
{
hours = h;
}
- (void) setMinutes:(int) m
{
minuts = m;
}
- (int) getHours
{
return hours;
}
- (int) getMinutes
{
return minuts;
}
-(void) printTime
{
NSLog(@"Time is %i:%i", hours, minuts);
}
@end
//the program section
int main(int argc, const char * argv[])
{
@autoreleasepool
{
Watch *myWatch = [[Watch alloc]init];
[myWatch getHours];
[myWatch getMinutes];
[myWatch setHours: 5];
[myWatch setMinutes: 30];
[myWatch printTime];
}
return 0;
}
Appreciate it in advance.
