oc-32-@property示例

Goods.h

#import <Foundation/Foundation.h>
typedef struct{
int year;
int month;
int day;
} MyDate; typedef enum{
GenderFemal,
Gendermal
} Gender; @interface Goods : NSObject
//已经做了set的内存管理
@property(nonatomic,assign)float price; // 单价 @property(nonatomic,assign)Gender gender; // 性别 @property(nonatomic,assign)float weight; // 重量 @property(nonatomic,copy)NSString *showImage; // 图片 @property(nonatomic,assign)MyDate produceDate; // 生产日期 @property(nonatomic,assign)MyDate expireDaer; // 过期日期 // 卖家所卖的商品
@property(nonatomic,retain)Goods *goods; @end

Good.m

#import "Goods.h"

@implementation Goods
- (void)dealloc
{
NSLog(@"商品被释放");
[super dealloc];
}
@end

main.m

#import <Foundation/Foundation.h>
#import "Goods.h"
#import "Buyer.h"
#import "Seller.h" int main(int argc, const char * argv[]) {
@autoreleasepool {
// 创建商品
Goods *g = [[Goods alloc] init];
// 给商品属性赋值
g.price = ;
g.weight = ;
g.showImage = @"/Users/apple/Desktop/1.png";
g.produceDate = (MyDate){,,};
g.expireDaer = (MyDate){,,}; // 买家
Buyer *buyer = [[Buyer alloc] init];
buyer.name = @"小明";
buyer.gender = GenderFemal;
buyer.age = ;
buyer.height = ; // 卖家
Seller *seller = [[Seller alloc] init];
seller.name = @"张三丰";
seller.age = ;
seller.height = ;
seller.goods = g; // 释放对象
[g release];
[buyer release];
[seller release]; }
return ;
}
上一篇:[知识点]SPFA算法


下一篇:C# - 创建List属性的简单方法