结构体作为对象属性

 1 //
 2 //  main.m
 3 //  结构体作为对象属性
 4 //
 5 //  Created by 李鑫 on 2017/2/22.
 6 //  Copyright © 2017年 CCSU. All rights reserved.
 7 //
 8 
 9 #import <Foundation/Foundation.h>
10 
11 typedef struct{
12     char *name;
13     int year;
14 } visitor;
15 
16 @interface MoonLack :NSObject{
17     @public
18     int _visitingDay;
19     visitor vis;
20 
21 
22 }
23 @end
24 
25 @implementation MoonLack{
26 
27 
28 }
29 
30 @end
31 
32 int main(int argc, const char * argv[]) {
33     MoonLack *ML = [MoonLack new];
34     ML->_visitingDay =222;
35     ML->vis=(visitor){"Simplelee",1992};
36     NSLog(@"This day is %d,the visitor's name is %s,his birthyear is %d",ML->_visitingDay,ML->vis.name,ML->vis.year);
37     return 0;
38 }

 

posted @ 2017-02-22 08:13  BeanPaste  阅读(207)  评论(0编辑  收藏  举报