FROM : mmalcolm crawford
DATE : Fri Apr 29 20:37:48 2005
On Apr 29, 2005, at 11:24 AM, Marc Blatt wrote:
> This may be something obvious that I am missing, but how do you
> save an image file (let's say jpeg) with Core Data into the object
> graph. The obvious way is storing by reference with an attribute
> that saves the string name. However, how would you actually store
> the image within the binary or sql file? Still trying to grasp Core
> Data's power...
>
It's not clear what you mean by "save an image file" in the context
of your suggestion of "storing by reference with an attribute that
saves the string name".
I assume you'll actually be storing the the image data as an NSData
object, in which case you can specify a data attribute of an entity
that holds the image data. If not, you can specify a string
attribute that identifies a file location (obviously this is a little
more fragile if files may be moved independently of your application).
If you want to store the image data in your file, first you should
not use the XML store (as you already imply). Second, I would
suggest that you actually use the SQLite store and if an entity
conceptually has a large data blob as an attribute that you actually
specify a separate entity for that attribute. For example, if a
Person entity should have a 'photo' attribute, then create a Photo
entity with just a single attribute -- the data -- and if you care a
relationship back to the Person (typically modeling relationships in
both directions is a Good Thing). Then create a relationship from
the Person to the Photo entity. This will mean that photo data is
only loaded from the persistent store if you actually use it.
mmalc
DATE : Fri Apr 29 20:37:48 2005
On Apr 29, 2005, at 11:24 AM, Marc Blatt wrote:
> This may be something obvious that I am missing, but how do you
> save an image file (let's say jpeg) with Core Data into the object
> graph. The obvious way is storing by reference with an attribute
> that saves the string name. However, how would you actually store
> the image within the binary or sql file? Still trying to grasp Core
> Data's power...
>
It's not clear what you mean by "save an image file" in the context
of your suggestion of "storing by reference with an attribute that
saves the string name".
I assume you'll actually be storing the the image data as an NSData
object, in which case you can specify a data attribute of an entity
that holds the image data. If not, you can specify a string
attribute that identifies a file location (obviously this is a little
more fragile if files may be moved independently of your application).
If you want to store the image data in your file, first you should
not use the XML store (as you already imply). Second, I would
suggest that you actually use the SQLite store and if an entity
conceptually has a large data blob as an attribute that you actually
specify a separate entity for that attribute. For example, if a
Person entity should have a 'photo' attribute, then create a Photo
entity with just a single attribute -- the data -- and if you care a
relationship back to the Person (typically modeling relationships in
both directions is a Good Thing). Then create a relationship from
the Person to the Photo entity. This will mean that photo data is
only loaded from the persistent store if you actually use it.
mmalc
| Related mails | Author | Date |
|---|---|---|
| Marc Blatt | Apr 29, 20:24 | |
| mmalcolm crawford | Apr 29, 20:37 | |
| Jim Correia | Apr 29, 22:41 | |
| mmalcolm crawford | Apr 29, 23:16 | |
| Scott Ellsworth | Apr 29, 23:32 | |
| mmalcolm crawford | Apr 30, 01:25 | |
| Scott Ellsworth | Apr 30, 02:14 | |
| Jim Correia | May 10, 19:11 |






Cocoa mail archive

