How to check if the Dictionary contains a key iOS swift?

Problem:
You had dictionary and it contains some set of keys.But you want to check the key exists before get the value.

Solution:

The function will return if key already there then true otherwise returns false


    func getIfKeyExists(dict:NSDictionary,key:String) ->Bool {
        if dict[key] == nil {
            return false
        } else {
            return true
        }
    }

 

Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

Saved Image in document directory and save path in coredata not able to fetch the image file iOS swift