最近我一直在試圖找出如何初始化一個字典中迅速不像我以前在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