iphone 常用函数汇总
2012-02-17 11:28
309 查看
1:将字典中的键值对赋值给对象的各个成员变量。关键字:setValuesForKeysWithDictionary
1.1先定义一个类,该类为Quotation 声明如下:
@interface Quotation : NSObject {
}
@property (nonatomic, retain) NSString *character;
@property (nonatomic, assign) NSInteger act;
@property (nonatomic, assign) NSInteger scene;
@property (nonatomic, retain) NSString *quotation;
@end
@implementation Quotation
@synthesize character, act, scene, quotation;
- (void)dealloc {
[character release];
[quotation release];
[super dealloc];
}
@end
1.2 然后自动从字典中将值取到对象中。使用了“setValuesForKeysWithDictionary”这么一个函数,代码如下:
NSArray *quotationDictionaries = [playDictionary objectForKey:@"quotations"];
NSMutableArray *quotations = [NSMutableArray arrayWithCapacity:[quotationDictionaries count]];
for (NSDictionary *quotationDictionary in quotationDictionaries) {
Quotation *quotation = [[Quotation alloc] init];
[quotation setValuesForKeysWithDictionary:quotationDictionary];
[quotations addObject:quotation];
[quotation release]; }
1.1先定义一个类,该类为Quotation 声明如下:
@interface Quotation : NSObject {
}
@property (nonatomic, retain) NSString *character;
@property (nonatomic, assign) NSInteger act;
@property (nonatomic, assign) NSInteger scene;
@property (nonatomic, retain) NSString *quotation;
@end
@implementation Quotation
@synthesize character, act, scene, quotation;
- (void)dealloc {
[character release];
[quotation release];
[super dealloc];
}
@end
1.2 然后自动从字典中将值取到对象中。使用了“setValuesForKeysWithDictionary”这么一个函数,代码如下:
NSArray *quotationDictionaries = [playDictionary objectForKey:@"quotations"];
NSMutableArray *quotations = [NSMutableArray arrayWithCapacity:[quotationDictionaries count]];
for (NSDictionary *quotationDictionary in quotationDictionaries) {
Quotation *quotation = [[Quotation alloc] init];
[quotation setValuesForKeysWithDictionary:quotationDictionary];
[quotations addObject:quotation];
[quotation release]; }
相关文章推荐
- 汇总c#.net常用函数和方法集
- oracle常用函数汇总(分享)
- *汇总c#.net常用函数和方法集
- EXCELVBA字符串处理常用函数汇总
- 数学建模常用Matlab/Lingo/c代码总结系列——Matlab图形绘制函数汇总
- Oracle -- plsql常用函数汇总
- ORACLE 维护常用函数汇总
- C/C++常用头文件及函数汇总
- Oracle常用函数汇总
- C/C++常用头文件及函数汇总
- 常用的PB时间函数汇总
- mysql常用函数汇总(分享)
- oracle常用函数汇总——数字函数
- OAF_OAF Framework常用函数汇总(概念)(转)
- C#常用函数和方法集汇总
- C++编程题最常用函数汇总
- C#常用函数和方法集汇总
- C# 常用函数和方法集汇总
- 汇总c#.net常用函数和方法集
- SQL的基本命令和几个常用函数汇总