I have looked at the examples of how to prevent this error, but the examples don't work without a significant lot of opening and closing database reads.
I have a routine that checks whether a stock code exists which obviously uses the database. The routine is called from a formatter from getObjectValue( for string: String, errorDescription error: ) -> Bool and this the formatter is called also when anything is written to that field. There is no way I can see of altering getObjectValue to get passed a database parameter. This means that if I read a database and fill in a stock code, I have to close the database read, write the stock code and then re-open it again which is very messy. And I cannot remove the validation, as I want to be able to alter the stock code.