Objective C Data Caching on iOS

前端 未结 6 1638
北海茫月
北海茫月 2021-02-01 21:30

I am pulling data from an API and then building out my data objects with it. I want to cache this data for the future. I have been storing the string from the api in NSUserDef

相关标签:
6条回答
  • 2021-02-01 21:31

    Have you noticed the NSCache?

    An NSCache object is a mutable collection that stores key-value pairs, similar to an NSDictionary object. The NSCache class provides a programmatic interface to adding and removing objects and setting eviction policies based on the total cost and number of objects in the cache...

    0 讨论(0)
  • 2021-02-01 21:31

    What type of data? If its text/string bases SQLLite would probably be the best.

    0 讨论(0)
  • 2021-02-01 21:31

    I'd store the computed/parsed data in either a Core Data store, or in NSData flat files in your application's Documents directory. You're correct that storing that in NSUserDefaults and then re parsing feels a little overkill.

    0 讨论(0)
  • 2021-02-01 21:34

    Personally I'm quite fond of the EGOCache classes, I use them quite a lot in my projects:

    https://github.com/enormego/EGOCache

    The classes are easy to use, I used to have my own classes with a similar design, but these are just more well-rounded, so I decided to stick with them (don't wanna reinvent the wheel).

    0 讨论(0)
  • 2021-02-01 21:35

    I vote Core Data

    0 讨论(0)
  • 2021-02-01 21:47

    There are many different solutions to this problem and there is no "right" way to do it. A few popular options are:

    • Core Data - Apple's framework for persistence. Very performant, but more difficult.
    • SQLite - Fast and flexible, but bare bones.
    • Plists - Basically writing a file to disk, you have to read and write manually.
    • NSUserDefaults - The lightest weight "key-value" option.

    I would encourage you to read up on all four and see which one works best for you.

    0 讨论(0)
提交回复
热议问题