.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
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。