Swift:[__ NSPlaceholderDictionary initWithObjects:forKeys:count:]:尝试从对象[1]'中插入nil对象

时间:2014-06-13 16:55:09

标签: swift

我有一个UITextView,我想将这个文本存储在NSDictionary中。

我有这段代码:

 var imageData = UIImageJPEGRepresentation(photoInfo["UIImagePickerControllerOriginalImage"] as UIImage, 100.0)

        var description = photoDesc.text

        println(description)

        var parameters: NSDictionary = ["user":"admin", "desc" : description, "image" : imageData]

        println(parameters)

println()输出"说明"正确,但我的代码崩溃在这一行:var参数:NSDictionary = ["user":"admin", "desc" : description, "image" : imageData]

出现此错误:

[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[1]'

如果我删除" desc"来自NSDictionary的密钥,我没有收到任何错误。

有什么想法吗?

解决:

var description: String = photoDesc.text

1 个答案:

答案 0 :(得分:2)

您无法将nil存储在NSDictionary中。相反,请为NSNull传递description