-1
对象的C风格的Swift如何制作字典数组?
@interface TestViewController:UIViewController{
NSArray *dataList;
}
@end
@implementation TestViewController
- (void)viewDidLoad
{
[super viewDidLoad];
NSDictionary *dict1 =[[NSDictionary alloc] initWithObjectsAndKeys:@"32",@"age",@"andy",@"name", nil];
NSDictionary *dict1 =[[NSDictionary alloc] initWithObjectsAndKeys:@"34",@"age",@"smith",@"name", nil];
NSDictionary *dict1 =[[NSDictionary alloc] initWithObjectsAndKeys:@"27",@"age",@"jonathan",@"name", nil];
dataList = [[NSArray alloc]initWithObjects:dict1,dict2,dict3,nil];
}
@end
我想让相同的代码在斯威夫特
所以我打字迅速风格如下
class ViewController: UIViewController {
var datalist = [Dictionary]() //Compile Error -> "Missing argument for parameter #1 in call"
// I can't understand error. What does it mean?
override func viewDidLoad() {
super.viewDidLoad()
let dict1 = ["age":"32","name":"andy"]
let dict2 = ["age":"34","name":"smith"]
let dict3 = ["age":"27","name":"jonathan"]
datalist = [dict1,dict2,dict3] //Compile Error -> 'ViewController' does not have a member named 'datalist'
}
}
但2错误
我不知道为什么发生错误
你能帮我吗?
真的很感谢你 – user1272854 2014-10-19 04:32:14