将Swift Dictionary转换为NSDictionary

前端之家收集整理的这篇文章主要介绍了将Swift Dictionary转换为NSDictionary前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我创建了一个 Swift Dictionary对象
var params = ["first_name": firstNameTextField.text,"last_name": lastNameTextField.text,"company": companyTextField.text,"email_address": emailTextField.text,"phone_number": phoneTextField.text]@H_502_2@ 
 

接下来,我有ObjC框架,我连接到我的Swift应用程序.
里面有一个属性对象

@property (nonatomic,retain) NSMutableDictionary *fields;@H_502_2@ 
 

我试图以这种方式分配它

object.fields = params@H_502_2@ 
 

并得到一个错误

Cannot convert the expression's type '()' to type 'NSMutableDictionary!'@H_502_2@ 
 

我也试过这样做

var params = ["first_name": firstNameTextField.text,"phone_number": pnoneTextField.text].mutableCopy() as NSMutableDictionary

object.fields = params@H_502_2@ 
 

编译得很好,但我遇到了运行时错误

*** Terminating app due to uncaught exception 'NSInvalidArgumentException',reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: 
attempt to insert nil object from objects[0]'@H_502_2@ 
 

我打印了所有字段,但它们不是零:

println(firstNameTextField.text)
println(lastNameTextField.text)
println(companyTextField.text)
println(emailTextField.text)
println(pnoneTextField.text)

...

1
2
3
5
4@H_502_2@ 
 

有任何想法吗?

尝试parms.bridgeToObjectiveC().但是,这可能会给你一个NSDictionary而不是NSMutableDictionary.

猜你在找的Swift相关文章