您好,登錄后才能下訂單哦!
.h文件。。。。。。。
@interface book : NSObject /*{ NSString *_bookName; //書名 CGFloat _bookThickness; //厚度 NSString *_bookType; //書類型 NSInteger _bookPrice; //書價格 NSString *_publishingHouse;//出版社 NSString *_publishintTime; //出版時間 }*/ //在@property里面,其實就包含了定義實例變量,setter方法和getter方法。這里可以不用在定義實例變量了 @property (nonatomic , copy)NSString *bookName;//用copy寫完整的屬性 @property (nonatomic , assign)CGFloat bookThickness; @property (nonatomic , retain)NSString *bookType;//retain不建議使用,大多使用copy @property (nonatomic , assign)NSInteger bookPrice; @property (nonatomic , copy)NSString *publishingHouse; @property (nonatomic , copy)NSString *publishintTime; - (void)read; - (void)write; @end
.m文件
@implementation book @synthesize bookName = _bookName ; @synthesize bookThickness = _bookThickness; @synthesize bookType = _bookType; @synthesize bookPrice = _bookPrice; @synthesize publishingHouse = _publishingHouse; @synthesize publishintTime = _publishintTime; - (void)setBookName:(NSString *)bookName { if (_bookName != bookName) { [_bookName release];//auto---All---Combined---Language--Objective C--->no這里是對內存的一個設置, _bookName = [bookName copy]; } } - (NSString *)bookName { return [[_bookName retain] autorelease]; } - (void)setBookThickness:(CGFloat)bookThickness { _bookThickness = bookThickness; } - (CGFloat)bookThickness { return _bookThickness; } - (void)setBookType:(NSString *)bookType { if (_bookType != bookType) { [_bookType release]; _bookType = [bookType retain];//retain和copy唯一的不同在這里。 } } - (NSString *)bookType { return [[_bookType retain] autorelease]; } - (void)setBookPrice:(NSInteger)bookPrice { _bookPrice = bookPrice; } - (NSInteger)bookPrice { return _bookPrice; } - (void)setPublishingHouse:(NSString *)publishingHouse { if (_publishingHouse != publishingHouse) { [_publishingHouse release]; _publishingHouse = [publishingHouse copy]; } } - (NSString *)publishingHouse { return [[_publishingHouse retain] autorelease]; } - (void)setPublishintTime:(NSString *)publishintTime { if (_publishintTime != publishintTime) { [_publishintTime release]; _publishintTime = [publishintTime copy]; } } - (NSString *)publishintTime { return [[_publishintTime retain] autorelease]; } - (void)read; { NSLog(@"這是一本書"); } - (void)write { NSLog(@"可以寫"); } @end
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。