I have the following code for a dictionary
var dic : [String: AnyObject] = ["FirstName": "Anvar", "LastName": "Azizov", "Website": NSNull(),"About": NSNull()]
I am already deleting a key that has a null value using the code below
var keys = dic.keys.array.filter({dic[$0] is NSNull})
for key in keys {
dic.removeValueForKey(key)
}
It works for a static dictionary, but I want to do it dynamically, I want to do it with a function, but whenever I pass the dictionary as an argument, it works like a let symbol, so it cannot delete the null key I am doing the code below for this
func nullKeyRemoval(dic : [String: AnyObject]) -> [String: AnyObject]{
var keysToRemove = dic.keys.array.filter({dic[$0] is NSNull})
for key in keysToRemove {
dic.removeValueForKey(key)
}
return dic
}
tell me the solution for this
source
share