最近我一直在试图找出如何初始化一个字典中迅速不像我以前在Objective-C的事情:的NSDictionary初始化与多个对象和键
NSMutableDictionary *loginDictionary = [[NSMutableDictionary alloc] initWithObjects:@[UsernameTextfield.text,PasswordTextfield.text] forKeys:@[@"username",@"password"];
我试图把它写在斯威夫特:
let userDictionary = NSMutableDictionary.init(object: [usernameTextField.text,passwordTextField.text], forKey: ["username","password"])
,但我得到一个错误:
Contextual type AnyObject cannot be used with array literal.
你可以(也应该)与'let'申报的NSMutableDictionary,因为它是一个*引用类型* ... –
@MartinR谢谢,我已经解决了我的答案。 – Moritz