I have a code where I want to set value for key as following:
item.setValue(field.1, forKey: field.0)
and I want to catch if the NSUnknownKeyException is thrown but I have the following code and it is not working:
do {
try item.setValue(field.1, forKey: field.0)
} catch _ {
print("Trying to set wrong value for the item ")
}
The displayed error when it is a not valid key is the following:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: setValue:forUndefinedKey:
How can I catch this exception?
Any help will be appreciated.