【发布时间】:2014-12-14 03:15:51
【问题描述】:
object-C 风格
@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
我想在 Swift 中编写相同的代码
所以我输入了如下的swift样式
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 错误
不知道为什么会报错
你能帮帮我吗?
【问题讨论】:
标签: arrays dictionary collections swift