- MyClass.h
#import <Foundation/Foundation.h> @interface MyClass : NSObject { NSString *name; NSInteger age; } @property (nonatomic, retain) NSString *name; @property NSInteger age; @end
- MyClass.m
#import "MyClass.h" @implementation MyClass @synthesize name, age; @end
- 實際使用
MyClass *myClass = [MyClass alloc]; //--setter myClass.name = @"Hank"; //--getter NSLog(@"%@", myClass.name); NSLog(@"%@", [myClass name]);
Reference
Beginning-iOS-4-Application-Development
The Objective-C Programming Language: Defining a Class