Skip to content

Commit

Permalink
Add enum example
Browse files Browse the repository at this point in the history
Add enum example
  • Loading branch information
CoderMJLee committed Feb 10, 2015
1 parent a7f19a1 commit f735c4f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 7 additions & 0 deletions MJExtensionExample/MJExtensionExample/Classes/User.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

#import <Foundation/Foundation.h>

typedef enum {
SexMale,
SexFemale
} Sex;

@interface User : NSObject
/** 名称 */
@property (copy, nonatomic) NSString *name;
Expand All @@ -19,4 +24,6 @@
@property (copy, nonatomic) NSString *height;
/** 财富 */
@property (strong, nonatomic) NSNumber *money;
/** 性别 */
@property (assign, nonatomic) Sex sex;
@end
5 changes: 3 additions & 2 deletions MJExtensionExample/MJExtensionExample/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ void keyValues2object()
@"icon" : @"lufy.png",
@"age" : @20,
@"height" : @1.55,
@"money" : @"100.9"
@"money" : @"100.9",
@"sex" : @(SexFemale)
};

// 2.将字典转为User模型
User *user = [User objectWithKeyValues:dict];

// 3.打印User模型的属性
NSLog(@"name=%@, icon=%@, age=%d, height=%@, money=%@", user.name, user.icon, user.age, user.height, user.money);
NSLog(@"name=%@, icon=%@, age=%d, height=%@, money=%@, sex=%d", user.name, user.icon, user.age, user.height, user.money, user.sex);
}

/**
Expand Down

0 comments on commit f735c4f

Please sign in to comment.