1c71 / Learn-iOS

学 iOS
0 stars 0 forks source link

iOS 学习笔记2 - OC #3

Open 1c7 opened 9 years ago

1c7 commented 9 years ago

定义类


@interface ClassName : SuperClass

@end


实现类

@implementation ClassName

@end


定义类更具体一点

@interface MyClass : NSObject

- (void)doSomething;

@end


实现类更具体一点


@implementation MyClass

- (void)doSomething {
    ...
}

@end
1c7 commented 9 years ago

调用同一个类里的其他方法

- (void)someMethod {
    ...
    [self someOtherMethod];
    ...
}


声明类属性

这样声明:

@property Type propertyName

更完全的写法如下

@interface Person : NSObject

@property NSString *firstName;
@property NSString *lastName;
@property NSUInteger age;

@end