首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

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

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

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


热点排行