Database Reference
In-Depth Information
Don't worry if the order of the attributes is different - all that matters is that the
attribute names and types are correct.
Note:
You may have noticed you have three options for the
timesWorn
integer
attribute:
Integer 16
,
Integer 32
or
Integer 64
.
16, 32 and 64 refer to the number of bits that represent the integer. This is
important for two reasons: the number of bits reflects how much space an
integer takes up on disk as well as how many values it can represent, or its
“range.” Here are the ranges for the three types of integers:
Range for 16-bit integer: -32768 to 32767
Range for 32-bit integer: -2147483648 to 2147483647
Range for 64-bit integer: -9223372036854775808 to 9223372036854775807
How do you choose? The source of your data will dictate the best type of
integer. You are assuming your users
really
like bow ties, so a 32-bit integer
should offer enough storage for a lifetime of bow tie wear. :]
Each bow tie has an associated image. How will you store it in Core Data? Add one
more attribute to the
Bowtie
entity, naming it
photoData
and changing its data
type to
Binary Data
:
Core Data also provides the option of storing arbitrary blobs of binary data directly
in your data model. These could be anything from images to PDF files, or anything
else that can be serialized into zeroes and ones.
As you can imagine, this convenience can come at a steep cost. Storing a large
amount of binary data in the same SQLite database as your other attributes will
likely impact your app's performance. That means a giant binary blob would be
loaded into memory each time you access an entity, even if you only need to
access its name!
Luckily, Core Data anticipates this problem. With the
photoData
attribute selected,
open the
Attributes
inspector and check the
Allows External Storage
option: