`
sillycat
  • 浏览: 2539724 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Learn Objective C(2)Learn Objective-C in Day 6 - 4 ~ 6

 
阅读更多

Learn Objective C(2)Learn Objective-C in Day 6 - 4 ~ 6

Car Example
Command-N (File ----> New File) ----> Cocoa Class under Mac OS X and select Objective-C
Name the class as SimpleCar and make it inherent from NSObject.

Interface and Implementation Coding
#import <Foundation/Foundation.h>

@interface SimpleCar : NSObject   

     @property (weak, nonatomic) NSString *make;   

     @property (weak, nonatomic) NSString *model;   

     @property (weak, nonatomic) NSNumber *vin;

 

      -(void) setMake:(NSString*)newMake      

                     andModel:(NSString*)newModel;
@end

That is the interface.

#import "SimpleCar.h"

@implementation SimpleCar

       @synthesize make, model, vin;

 

       -(void) setMake:(NSString *)newMake      

              andModel:(NSString *)newModel{   

                   [selfsetMake: newMake];   

                   [selfsetModel: newModel];

       }
@end

Here is the implementation. @properties and @synthesize make it easy to do something like getter and setter.



References:
http://mobile.tutsplus.com/tutorials/iphone/learn-objective-c-day-4/
http://mobile.tutsplus.com/tutorials/iphone/learn-objective-c-day-5/
http://mobile.tutsplus.com/tutorials/iphone/learn-objective-c-day-6/

Objective C Book from Apple
https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/Introduction/Introduction.html


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics