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 = 100;
        g.weight = 100;
        g.showImage = @"/Users/apple/Desktop/1.png";
        g.produceDate = (MyDate){2015,10,15};
        g.expireDaer = (MyDate){2015,10,16};
        
        // 买家
        Buyer *buyer = [[Buyer alloc] init];
        buyer.name = @"小明";
        buyer.gender = GenderFemal;
        buyer.age = 20;
        buyer.height = 141;
        
        // 卖家
        Seller *seller = [[Seller alloc] init];
        seller.name = @"张三丰";
        seller.age = 18;
        seller.height = 137;
        seller.goods = g;
        
        // 释放对象
        [g release];
        [buyer release];
        [seller release];
        
    }
    return 0;
}
复制代码

 


本文转自农夫山泉别墅博客园博客,原文链接:http://www.cnblogs.com/yaowen/p/5314562.html,如需转载请自行联系原作者
相关文章
|
9月前
|
Java 数据库
SpringBoot整合es7.x启动报错:Rejecting mapping update to [AAA] as the final mapping would have more than 1
SpringBoot整合es7.x启动报错:Rejecting mapping update to [AAA] as the final mapping would have more than 1
207 1
flowable项目报错:java.sql.SQLSyntaxErrorException: Table ‘psr_flowable_test.act_ge_property’ doesn’t exi
flowable项目报错:java.sql.SQLSyntaxErrorException: Table ‘psr_flowable_test.act_ge_property’ doesn’t exi
225 0
|
Java 数据库连接 mybatis
mybatis报错:Type handler was null on parameter mapping or property ‘__frch_xxx_0’
mybatis报错:Type handler was null on parameter mapping or property ‘__frch_xxx_0’
2205 0
mybatis报错:Type handler was null on parameter mapping or property ‘__frch_xxx_0’
|
10月前
|
Java
Error:(15, 13) java: No property named “id” exists in source parameter(s). Did you mean “null”?
Error:(15, 13) java: No property named “id” exists in source parameter(s). Did you mean “null”?
267 1
../../..xxx.go:46:18: aa.Bbb undefined (type *"xx/xxx/xx".Ccc has no field or method Bbb)
../../..xxx.go:46:18: aa.Bbb undefined (type *"xx/xxx/xx".Ccc has no field or method Bbb)
Error:(15, 13) java: No property named “id” exists in source parameter(s). Did you mean “null”?
Error:(15, 13) java: No property named “id” exists in source parameter(s). Did you mean “null”?
对‘avformat_find_stream_info’未定义的引用、to the PKG_CONFIG_PATH environment variable
对‘avformat_find_stream_info’未定义的引用、to the PKG_CONFIG_PATH environment variable
105 0
MapStruct - No property named “XXX“ exists in source parameter(s). Did you mean “null“?
MapStruct - No property named “XXX“ exists in source parameter(s). Did you mean “null“?
1672 0
|
程序员 编译器 C语言
解决办法:undefined reference to symbol '_ZTVN10__cxxabiv117__class_type_infoE@@CXXABI_1.3
解决办法:undefined reference to symbol '_ZTVN10__cxxabiv117__class_type_infoE@@CXXABI_1.3
976 0