baya / my-tech-ios

https://github.com/baya/my-tech-ios/issues
0 stars 0 forks source link

Objective-C 怎样实现一个class #6

Open baya opened 10 years ago

baya commented 10 years ago

相关链接

http://cocoadevcentral.com/d/learn_objectivec/ http://rypress.com/tutorials/objective-c/classes.html

速读

类的实现分 Interface 和 Implementation 两个部分

Interface

#import <Cocoa/Cocoa.h>

@interface Photo : NSObject {
    NSString* caption;
    NSString* photographer;
 }

 - caption;
 - photographer;

@end        

NSObject是Photo的父类

  • 表示实例方法
    • 表示类方法

      Implementation

#import "Photo.h"

@implementation Photo

   - (NSString*) caption {
       return caption;
    }

   - (NSString*) photographer {
      return photographer;
    }
@end

Init

Dealloc