我创建了一个Swift Dictionary对象
var params = ["first_name": firstNameTextField.text,
"last_name": lastNameTextField.text,
"company": companyTextField.text,
"email_address": emailTextField.text,
"phone_number": phoneTextField.text]
Run Code Online (Sandbox Code Playgroud)
接下来,我有ObjC框架,我连接到我的Swift应用程序.里面有一个属性对象
@property (nonatomic, retain) NSMutableDictionary *fields;
Run Code Online (Sandbox Code Playgroud)
我正试图以这种方式分配它
object.fields = params
Run Code Online (Sandbox Code Playgroud)
并得到一个错误:
Cannot convert the expression's type '()' to type 'NSMutableDictionary!'
Run Code Online (Sandbox Code Playgroud)
我也试过这样做
var params = ["first_name": firstNameTextField.text,
"last_name": lastNameTextField.text,
"company": companyTextField.text,
"email_address": emailTextField.text,
"phone_number": pnoneTextField.text].mutableCopy() as NSMutableDictionary
object.fields = params
Run Code Online (Sandbox Code Playgroud)
编译得很好,但我遇到了运行时错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]:
attempt to insert nil object from objects[0]'
Run Code Online (Sandbox Code Playgroud)
我打印了所有字段,但它们不是零:
println(firstNameTextField.text)
println(lastNameTextField.text)
println(companyTextField.text)
println(emailTextField.text)
println(pnoneTextField.text)
...
1
2
3
5
4
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
试试parms.bridgeToObjectiveC().但是,这可能会给你一个NSDictionary而不是NSMutableDictionary.
| 归档时间: |
|
| 查看次数: |
12332 次 |
| 最近记录: |