CoreData or single files (iOS)

I have a little mystery: would it be better to use direct file management or a SQLite CoreData database?

Here is my scenario:

I have a bunch of "custom" objects, each with a list of "post" objects. This is easy to do in CoreData, and it would be great - however, the "post" objects are downloaded from the web server, and each of them has a unique identifier. I do not want to have multiple post objects with the same ID. I could solve this by caching CoreData responses in an NSDictionary, however this will not reflect the design structure of the application well. As far as I know, when adding a new “message” to my CoreData NSManagedObjectContext, I would have to look for a unique identifier to check its existence (quickly), and then add it if it does not exist (slow), and update the previous one if it does ( quickly). This effectively replaces it. How do you guys handle this?

I have been trying to think about alternatives for several days, but no matter how I look at it, CoreData will be slower than my alternative:

The file architecture inside the Caches / iOS application directory may solve the problem. Something like that:

  • Users /
    • {unique identifier} .user
    • {unique identifier} .user
  • Messages /
    • {unique identifier} .post
    • {unique identifier} .post

Then, upon receiving the post object or user object, I can check the files for data and cache the contents of the file in NSDictionary. If the identifier exists in the dictionary, extract it there. Replacing previous user and post objects is as simple as overwriting a file and updating the cache.

, , - - , CoreData, , , .

- "uniquing" CoreData? . - SQLite.

, , , , , - .

+3
2

.

, Core Data . fetch , , , . , , , , .

, , Core Data. .

, - . , Core Data . , ? , , .

+3

, CoreData . , , : 1000 CoreData; 100 . , , 0,069 , , , 0,181. 3G iPad. , 10 , 4 .

: CoreData!

+2

Source: https://habr.com/ru/post/1764127/


All Articles