cocoa - iOS Core Data unique object fetch -
I am quite new to iOS / Cocoa and I have a very basic question about core data. I was looking for an appropriate answer / solution on the internet but I was not able to.
The question is, how do you manage the specificity of the core data? I know that core data is not a database, something like an object graph. Let's say we have a unit named 'user' that has some relation with attribute 'id' and 'name' and other institutions. Now we want to update the name of a specific user (such as the web service gave us the ID and new name).
The way I did it earlier:
NSFetchRequest * request = [[NSFetchRequest alloc] init]; [Request Set Entity: [NSTTTD Decision Unit FERN: @ Managed Object Contains in "User": context]]; [Confirmed request: [NSPredicate predicateWithFormat: @ "id ==% @", anId]]; NSError * Error = Zero; NSArray * result = [reference executeFetchRequest: request error: & amp; Error]; User * User = [Results Final Object]; But I have heard that this is bad behavior. Is it because the request to bring with the forecast is very slow? I can not imagine that this is such a big deal, as far as I know that there is no other way to go on each object and instead of examining equality, there is no other way to get a unique object ..
Will it be more efficient to bring all the objects in the unit, looping them manually (instead of fetch requests) through an array and through it?
NSFetchRequest * request = [[NSFetchRequest alloc] init]; [Request Set Entity: [NSTTTD Decision Unit FERN: @ Managed Object Contains in "User": context]]; NSError * Error = Zero; NSArray * result = [reference executeFetchRequest: request error: & amp; Error]; User * results user; (User * in user result) {if ([user.id isqual: anId]) resultUser = user; } Please help me find the right path and thanks.
If you have an index for the property that you are bringing (the model editor has a checkbox ), It is really very efficient that uses a similarity to fetching. Actually, it is never more efficient to bring all the items and iterate into memory, but makes the difference in an index more important.
Comments
Post a Comment