标签:
Objective-c
类,对象,方法
实际的变量是类的一个实例。
实例能执行的操作称为方法。
[ClassOrInstance method];
定义类
@interface classname : superclass
define method as interface
类实现
@implementation class {
变量
}
methods
myFraction = [[Fraction alloc] init];
ex:
#import <Foundation/Foundation.h>
//#import "Fraction1.h"
//---------*.h
@interface Fraction : NSObject
-(void) print;
-(void) setNumerator: (int) n;
-(void) setDenominator : (int) d;
@end
//---------*.m
@implementation Fraction {
int numerator;
int denominator;
}
-(void) print {
NSLog(@"%i/%i", numerator, denominator);
}
-(void) setNumerator:(int)n {
numerator = n;
}
-(void)setDenominator:(int)d {
denominator = d;
}
@end
int main(int argc, const char * argv[]) {
@autoreleasepool {
Fraction *myFraction;
myFraction = [Fraction alloc];
myFraction = [myFraction init];
[myFraction setNumerator: 1];
[myFraction setDenominator: 3];
[myFraction print];
}
return 0;
}
@property @interface
@sysnthesize @implementation
self = this;
@class
继承与覆盖
抽象
多态
is* 来判断
@try {
}
@catch)NSException * ex) {
}
@finally
@throw
@protected
@private
@public
@package
enum枚举
typedef
第十章看完。
标签:
原文地址:http://my.oschina.net/dubenju/blog/531158