读书人

Learn Objective C(二)Learn Objectiv

发布时间: 2013-10-22 16:16:51 作者: rapoo

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


读书人网 >移动开发

热点推荐