Objective-c
Class, Object, method
The actual variable is an instance of the class.
The actions that an instance can perform are called methods.
[Classorinstance Method];
Defining classes
@interface Classname:superclass
Define method as interface
@end
Class implementation
@implementation Class {
Variable
}
Methods
@end
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
Inheritance and overrides
Abstract
Polymorphic
is* to judge
@try {
}
@catch) NSException * ex) {
}
@finally
@throw
@protected
@private
@public
@package
Enum enum
typedef
The tenth chapter is finished.
Objective-c (2)