Rorschach Rorschach - 1 year ago 91
Swift Question

Check if JSON as dictionary contains Optional(null)

I want to make an if statement that checks if my JSON (item_section) has a null value at a certain key.

This code:

let my_dict = item_section[counter].dictionaryValue

when the creator is not set.

If it is set if it prints the creator's name, like:

How can I make an if statement that checks if the creator is null?

Such as:

if ((my_dict["creator"]) == nil) { //This line does not work
my_dict["creator"] = "No Maker"

Answer Source


if my_dict["creator"].type == .Null {
    print("creator is null")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download