简体   繁体   中英

iPhone - database query returning non committed entries?

I have core data in my app. At some point I have to add a new event to the database. So I do:

anEvent = [NSEntityDescription insertNewObjectForEntityForName:@"Events" inManagedObjectContext:context];

this will give me a clean entry to start filling the values.

As soon as the user finishes filling all event properties and taps DONE, I have to check to see if there's another equal event on the database. The app cannot allow duplicate entries. So, if a duplicate event is detected on the database, the user gets a message and have to change something. If there's no duplicate, then I commit the entry to the database. Remember that the entry is just saved to the database if there's no duplicate there. I don't know how it is called on core data, but lets say that this entry that was not committed is in a kind of "wannabe entry buffer".

The problem is this: when I query the database to receive the entries, this wannabe entry is there. So every check for duplicate will result in true, obviously.

how can that be? How can an entry appear on the query if it was not committed to the database yet? am I missing something?

Yes, I am sure the entry was not committed yet at the point it is seen on the query.

thanks

The object is inserted in the context and your fetch request also works on the context. So probably the new item will be in your query.

You could use a workaround: save all data in local variables, check them and if the input is ok, create the new object and insert the data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM