Klian
Klian

Reputation: 1565

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

I have a UITextView and I want to store this text in a NSDictionary.

I have this piece of code:

 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() outputs "description" correctly, but my code crash in this line: var parameters: NSDictionary = ["user":"admin", "desc" : description, "image" : imageData]

with this error:

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

If I remove "desc" key from NSDictionary, I don't get any error.

Any idea ?

SOLVED:

var description: String = photoDesc.text

Upvotes: 1

Views: 4479

Answers (1)

Millie Smith
Millie Smith

Reputation: 4604

You can't store nil in NSDictionary. Pass NSNull for your description instead.

Upvotes: 2

Related Questions