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
}
}
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
Post a Comment