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 ;
}

oc-32-@property示例的更多相关文章

  1. OC语言@property @synthesize和id

    OC语言@property @synthesize和id 一.@property @synthesize关键字 注意:这两个关键字是编译器特性,让xcode可以自动生成getter和setter的声明 ...

  2. OC中@property属性关键字的使用(assign/weak/strong/copy)

    OC中@property属性关键字的使用(assign/weak/strong/copy) 一.assign 用于 ‘基本数据类型’.‘枚举’.‘结构体’ 等非OC对象类型 eg:int.bool等 ...

  3. 李洪强iOS开发之OC语言@property @synthesize和id

    OC语言@property @synthesize和id 一.@property @synthesize关键字 注意:这两个关键字是编译器特性,让xcode可以自动生成getter和setter的声明 ...

  4. OC基础--Property

    编译器指令: 用来告诉编译器要做什么 @property: @property是编译器的指令 告诉编译器在@interface中自动生成setter和getter的声明 @synthesize: @s ...

  5. [OC笔记]@property之个人理解,大神轻拍

    /** * 一个简单的对象 * * @author suzhen * */ public class SimpleObjcet { /** * 声明一个age字段 */ private Object ...

  6. OC的@property 和 @synthesize id

    学习java的JDBC,成员变量的setter和getter,eclipse都能帮我们自动生成:当然xcode这款编译器也很强大,也能自动生成: 1:@property @property是写在类的声 ...

  7. OC中property方法的使用

    我们直入主题,关于property方法,我们先来了解一下相关的知识,首先是成员变量,实例变量,属性变量. 我们定义一个类来看一下 @interface Person :NSObject{ NSInte ...

  8. OC中property的有关属性

    property的有关属性: (1)readwrite是可读可写特征:需要生成getter方法和setter方法: (2)readonly是只读特性只会生成getter方法不会生成setter方法: ...

  9. OC之property和自动释放池

    property实例 property参数 自动释放池 一.property实例 1.前边的例子我们看到,我们在一个类中如果用到另外一个类的实例作为自己的成员变量时,通常需要在setter方法中,先r ...

  10. 「OC」@property @synthesize和id

    一.@property @synthesize关键字 这两个关键字是编译器特性,让Xcode可以自动生成getter和setter. (一)@property 关键字 @property 关键字可以自 ...

随机推荐

  1. GC算法 垃圾收集器

    GC算法 垃圾收集器 参考:http://www.cnblogs.com/ityouknow/p/5614961.html 概述 垃圾收集 Garbage Collection 通常被称为“GC”,它 ...

  2. Mapreduce执行过程分析(基于Hadoop2.4)——(二)

    4.3 Map类 创建Map类和map函数,map函数是org.apache.hadoop.mapreduce.Mapper类中的定义的,当处理每一个键值对的时候,都要调用一次map方法,用户需要覆写 ...

  3. hadoop-1.2.0源码编译

    以下为在CentOS-6.4下hadoop-1.2.0源码编译步骤. 1. 安装并且配置ant 下载ant,将ant目录下的bin文件夹加入到PATH变量中. 2. 安装git,安装autoconf, ...

  4. openstack-dbs

    真正的服务器派生出线程 和子进程处理多个连接当允许客户端加入聊天室,他发送的任何一条文本都将广播给聊天室中的每个用户,除非文本是服务器CLI当广播一条消息,消息前面将加上发送者的昵称 以尖括号括住昵称 ...

  5. 第三百五十二天 how can I 坚持

    如果要是今年找不到对象,明年去回济南, 怎么感觉那么不舍呢.生活总是有太多的无奈啊. 今天加了一天,倒是没感觉,只是感觉生活太空虚. 或许遗憾只是因为自己太懦弱.怎么说呢,还是那句话,经历的就会成长, ...

  6. VS2010在C#头文件添加文件注释的方法(转)

    步骤: 1.VS2010 中找到(安装盘符以C盘为例)C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplatesCa ...

  7. Debugging Information in Separate Files

    [Debugging Information in Separate Files] gdb allows you to put a program's debugging information in ...

  8. 新 esb-cs-tool.jar 参数说明

    旧esb-cs-tool.jar 使用说明 : invoke(RequestBusinessObject requestBo) 旧参数说明: requestBo  : 封装好的请求参数大对象  Req ...

  9. CodeForces 534B Covered Path (水题)

    题意:给定两个速度,一个一初速度,一个末速度,然后给定 t 秒时间,还每秒速度最多变化多少,让你求最长距离. 析:其实这个题很水的,看一遍就知道怎么做了,很明显就是先从末速度开始算起,然后倒着推. 代 ...

  10. 判断时间大小 yyyy-MM-dd 格式

    // yyyy-MM-dd function bigThanToday(someDate){ var date = new Date(); var dateStr = date.getFullYear ...