CoreData : store images to DB or not?

后端 未结 2 983
不思量自难忘°
不思量自难忘° 2020-12-02 07:54

I am making an app that takes photos from web site for some Username and shows it in a UITable with username then when clicking user name it shows photos for this user and t

相关标签:
2条回答
  • 2020-12-02 08:45

    You can simply store UIImage objects in CoreData directly, just use Transformable data type, and you are ready to go

    0 讨论(0)
  • 2020-12-02 08:49

    First, always store your images in a usable format such as PNG or JPEG instead of NSData. This will save you a lot of headaches.

    Second, the rule for storing binary data is:

    • < 100kb store in the same table as the relevant data
    • < 1mb store in a separate table attached via a relationship to avoid loading unnecessarily
    • 1mb store on disk and reference it inside of Core Data

    Update

    The storage inside of Core Data should be binary and you can write accessor methods for it. Take a look at this answer: Core data images from desktop to iphone

    Update

    The example code I linked to describes how to create accessors in your NSManagedObject subclass that will convert the image back and forth between a UIImage and binary data.

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