【发布时间】:2009-01-10 22:51:19
【问题描述】:
在 python 中,很容易构建字典或数组并将其解包传递给带有可变参数的函数
我有这个:
- (BOOL) executeUpdate:(NSString*)sql, ... {
手动方式是这样的:
[db executeUpdate:@"insert into test (a, b, c, d, e) values (?, ?, ?, ?, ?)" ,
@"hi'", // look! I put in a ', and I'm not escaping it!
[NSString stringWithFormat:@"number %d", i],
[NSNumber numberWithInt:i],
[NSDate date],
[NSNumber numberWithFloat:2.2f]];
但我无法硬编码我想要调用的参数:
NSMutableArray *values = [NSMutableArray array];
for (NSString *fieldName in props) {
..
..
[values addObject : value]
}
[db executeUpdate:@"insert into test (a, b, c, d, e) values (?, ?, ?, ?, ?)" ,??values];
【问题讨论】:
标签: objective-c