(Ebook) Core Data: Apple's API For Persisting Data On Mac OS X by Marcus S. Zarra ISBN 9781934356326, 1934356328 Sample
(Ebook) Core Data: Apple's API For Persisting Data On Mac OS X by Marcus S. Zarra ISBN 9781934356326, 1934356328 Sample
Featured on ebooknice.com
( 4.7/5.0 ★ | 419 downloads )
https://ebooknice.com/product/core-data-apple-s-api-for-persisting-
data-on-mac-os-x-1311228
(Ebook) Core Data: Apple's API for Persisting Data on Mac OS
X by Marcus S. Zarra ISBN 9781934356326, 1934356328 Pdf
Download
EBOOK
Available Formats
(Ebook) Core Data in Swift: Data Storage and Management for iOS and OS
X by Marcus S. Zarra
https://ebooknice.com/product/core-data-in-swift-data-storage-and-
management-for-ios-and-os-x-55604558
(Ebook) Core Data: Data Storage and Management for iOS, OS X, and
iCloud by Marcus S. Zarra ISBN 9781937785086, 1937785084
https://ebooknice.com/product/core-data-data-storage-and-management-
for-ios-os-x-and-icloud-4573126
(Ebook) Core Data in Swift: Data Storage and Management for iOS and OS
X by Marcus S. Zarra ISBN 9781680501704, 1680501704
https://ebooknice.com/product/core-data-in-swift-data-storage-and-
management-for-ios-and-os-x-7419266
https://ebooknice.com/product/core-animation-simplified-animation-
techniques-for-mac-and-iphone-development-1295824
(Ebook) MAC OS X UNIX Toolbox: 1000+ Commands for the Mac OS X by
Christopher Negus ISBN 9780470478363, 0470478365
https://ebooknice.com/product/mac-os-x-unix-toolbox-1000-commands-for-
the-mac-os-x-1793620
https://ebooknice.com/product/apple-training-series-mac-os-x-support-
essentials-2nd-edition-apple-training-2008-1866156
(Ebook) Mac Kung Fu: Over 400 Tips, Tricks, Hints, and Hacks for Apple
OS X by Keir Thomas ISBN 9781937785079, 1937785076
https://ebooknice.com/product/mac-kung-fu-over-400-tips-tricks-hints-
and-hacks-for-apple-os-x-4587926
https://ebooknice.com/product/mac-os-x-and-ios-internals-to-the-apple-
s-core-4586762
https://ebooknice.com/product/core-animation-for-mac-os-x-and-the-
iphone-creating-compelling-dynamic-user-interfaces-1216986
What Readers Are Saying About
Core Data
I was putting off learning Core Data—and then I saw Marcus’s book.
Bought it, read it, learned Core Data. It even covers the hard things I
really needed to know but weren’t well written elsewhere: things like
Spotlight integration, version migration, syncing, and, most important
for me, multithreading.
Brent Simmons
Developer, NetNewsWire
If your application deals with data, you need Core Data. If you need
Core Data, you need to know Marcus Zarra.
Mike Lee
Engineer, United Lemur
This book does a wonderful job of leading you through Core Data’s
steep learning curve. Even experienced Core Data developers will
learn something new.
Jon Trainer
President, Outer Level
I have been using Core Data since it was introduced, and there were
still new techniques that I uncovered in this book.
Luis de la Rosa
Founder, Happy Apps LLC
Core Data
Apple’s API for Persisting Data on Mac OS X
Marcus S. Zarra
Every precaution was taken in the preparation of this book. However, the publisher
assumes no responsibility for errors or omissions, or for damages that may result from
the use of information (including program listings) contained herein.
Our Pragmatic courses, workshops, and other products can help you and your team
create better software and have more fun. For more information, as well as the latest
Pragmatic titles, please visit us at
http://www.pragprog.com
ISBN-10: 1-934356-32-8
ISBN-13: 978-1-934356-32-6
Printed on acid-free paper.
P1.0 printing, September 2009
Version: 2009-10-9
Contents
1 Introduction 8
1.1 What Is Core Data? . . . . . . . . . . . . . . . . . . . . . 9
1.2 In This Book . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.3 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . 12
6 Performance Tuning 97
6.1 Persistent Store Types . . . . . . . . . . . . . . . . . . . 97
6.2 Optimizing Your Data Model . . . . . . . . . . . . . . . . 99
6.3 Fetching . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
6.4 Faulting . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
6.5 Access Patterns . . . . . . . . . . . . . . . . . . . . . . . 112
Index 238
Chapter 1
Introduction
It is hard to believe that I have been working on this book for nine
months and that it is now complete. I freely admit that I walked into
this project with a lot of trepidation. There was simply no way that I
was going to fill an entire book about Core Data! Now looking back on
it, I realize how wrong I was. If you look at Core Data in a vacuum, then
it can be a fairly small subject, and believe me, that is a good thing. But
when we take it as part of the whole ecology of OS X, then it becomes
so much more, which makes it possible to write several books on the
subject.
Back when Core Data was first introduced, I was in the process of
designing a desktop application later to become known as Simple Ele-
gant Sales. This point-of-sale software was originally written for my wife
and her business as a photographer. I wanted her to be able to easily
handle the accounting of her business from her laptop as she traveled
from location to location. When I originally wrote the software, I had far
more experience with Java than with Objective-C, but I knew that if the
app was going to be taken seriously as an OS X application, the user
interface had to be written in Objective-C and Cocoa. A Java UI simply
would not do. However, I decided to write the back side of the applica-
tion in Java so that I could take advantage of the powerful databases
and relational mapping abilities of Hibernate.
I was about halfway through this project when I met Tom Harrington
of Atomic Bird (http://www.atomicbird.com). He suggested that I take a
look at Core Data for the back end of my software and that it might
suit my needs better than Java. At that time, Tiger had not yet been
released, and Core Data was still available only to developers. After
experimenting with it for just one day, I immediately went back to the
W HAT I S C ORE D ATA ? 9
Joe Asks. . .
Is This Book for You?
If you plan on writing an application that saves data to disk,
then you should be taking a very long look at Core Data.
Whether you are focusing on the desktop or the iPhone, Core
Data is the most efficient solution to data persistence.
A good way to confirm that you know enough Cocoa to bene-
fit from this book is to take a look at Chapter 2, Getting Started
with Core Data, on page 14. You should find that chapter
dense, but every step should be familiar to you.
drawing board, scratched the entire project, and started over. It was
that much of an improvement over what I was doing.
Since that day, I have been enraptured by Core Data, and I quickly
learned everything about it that I possibly could.
disk, but it is also all the objects in memory that we normally consider
to be data objects. If you have experience working with Java, C#, or
some other object-oriented language, the data objects take a lot of time
to write, and they are generally very repetitive in nature. Core Data
eliminates most, if not all, of that boilerplate code for us and lets us
focus on the business logic, or the controller layer, of our application.
It does this with an interface that is as easy to use as Interface Builder.
In addition to ease of use, Core Data is also highly flexible. If we need to
step in and change the functionality of some portion of the data model,
we can. From how a value is handled when it is being accessed to how
data is migrated from one persistent store to another, we can choose
how little or how much we want to code ourselves and how much we
want Core Data to do for us.
The original design and idea of Core Data came from Enterprise Ob-
jects, which is part of Web Objects, another Apple framework. You may
be surprised to learn that Enterprise Objects and Web Objects, the
ancestors of Core Data, still run a large portion of Apple’s public-facing
websites. Both iTunes and http://www.apple.com run on a Web Objects
server. Therefore, although Core Data is a relatively new technology for
the OS X desktop, it has a long lineage.
We are also not at the end of the story with Core Data. Although it
is a stable and mature framework that is being used by thousands of
applications on a daily basis, there are most certainly things coming in
the future that will make it even greater. Just comparing its abilities to
those of Enterprise Objects, we know that the best is yet to come. If you
are starting an application now, you should be using Core Data.
them very quickly. The goal of the chapter is to give us a frame upon
which to build as we explore the depths of Core Data. By the end of
the chapter, we will have a basic Core Data application running that we
can then expand upon.
In Chapter 3, Core Data and Bindings, on page 34, we will explore Key
Value Observing (KVO) and Key Value Coding (KVC), which are at the
heart of what makes Core Data such a powerful framework. Without
an understanding of KVO and KVC, the rest of Core Data will seem like
magic. Therefore, we will make sure we have a solid understanding of
how these technologies work and how they apply to Core Data.
Next in Chapter 4, Under the Hood of Core Data, on page 51, we will
explore the big pieces of Core Data. We will take each component and
grasp how it works with our application that we wrote and what it does
in the overall Core Data framework. I strongly recommend bookmarking
this chapter, because we will be utilizing its components through the
rest of the book.
In Chapter 5, Versioning and Migration, on page 73, we will explore
how to change our underlying data model once our application has
been released to the public. Mistakes happen, and more often than not,
improvements to an application cause a need for the data to change. In
this chapter we will explore how to handle the changes to data and how
to migrate it from one version to another. At the end of this chapter,
we will discuss a technique that makes versioning and migration easier
and reduces the amount of maintenance we need to perform.
In Chapter 6, Performance Tuning, on page 97, we take the components
we learned from Chapter 4 and explore how to make them run as fast
as possible. Although Core Data does a lot of work for us and is very
performant, it is still possible to do the wrong thing and slow it down.
In this chapter we will discuss some of the common mistakes made and
how to avoid them. With that knowledge, we will be better armed going
forward to avoid those mistakes so that we don’t have to go back and
fix them later.
In Chapter 7, Spotlight, Quick Look, and Core Data, on page 114, you’ll
learn about integrating our Core Data application with the rest of the
operating system. Nothing screams polish to me like an application that
works well with both Spotlight and Quick Look. In this chapter we will
learn how to make that happen in our application.
A CKNOWLEDGMENTS 12
In Chapter 8, Sync Services and Core Data, on page 140, we’ll discuss
ways in which we can sync the data that is in our application across
multiple instances. With more and more users having more than one
computer, it is ever more important to be able to keep data “in the
cloud” and sync it properly across machines. By the end of this chapter,
we will be able to add that functionality to our application.
In Chapter 9, Multithreading and Core Data, on page 162, you’ll see how
to maximize the use of the computing power available to us. Modern
desktops and laptops have more than one CPU available to use, and
if the situation demands it, it is expected that our applications will
take advantage of all that processing power in a parallel manner. In
this chapter, we explore the safe ways to make a Core Data application
multithreaded.
In Chapter 10, Core Data and iPhone, on page 184, we take a side step
to discuss how we can use the power and flexibility of Core Data to
make our iPhone development easier. In this chapter we will also be
introduced to a new controller object that does not currently exist on
the Desktop.
In Chapter 11, Recipe: Distributed Core Data, on page 207, we explore
one solution for using Core Data across a distributed environment. By
combining Core Data, Bonjour, and distributed objects, we can access
a Core Data repository from more than one client spread across a local
network. Although I would not recommend developing the next great
MMORPG with this solution, it certainly has its uses.
In Chapter 12, Recipe: Dynamic Parameters, on page 228, the final
chapter, I share one of my secrets that I used in Simply Elegant Sales
and have used several times since its original design. In this recipe, we
design a document-level properties storage system similar to NSUserDe-
faults.
By the end of this book, we will have a superior grasp of all that Core
Data can do along with many practical applications of this technology.
From here we can take that knowledge to build the next generation of
fantastic desktop applications.
1.3 Acknowledgments
When I first started working with Core Data, I enjoyed it so much that
I wanted to share all the discoveries that I had made with it. I soon
A CKNOWLEDGMENTS 13
want to use and at least some of the attributes. Therefore, we will start
with them. In our Xcode project, there is a group called Models, and
within that group is a file called DataModel.xcdatamodel.2 This file is a
representation of the data structure that Core Data will use. This file
has a lot of similarities to an entity-relationship diagram (ERD) except
that Xcode will compile it directly into our final data file structure.
Once the first attribute is finished, add the following attributes to the
Recipe object:
Joe Asks. . .
What Is One-to-Many?
One-to-many is a database term that describes the relation-
ship between two tables in the database. Normally, there
are three kinds of relationships: one-to-one, one-to-many, and
many-to-many. A one-to-one relationship means that for each
record in the first table there can be no more than one record
in the second table. In a one-to-many relationship, for each
record in the first table, there can be more than one record
in the second table. The last relationship type, many-to-many,
means that for any record in the first table, there can be
any number of records in the second table, and, likewise, for
each record in the second table, there can be any number of
records in the first table.
s impressive external
lodgings a to
save
their
boy amazing
most words
We
trotted
end and
to
ezzel
schooners
Who hangsulyoznom
where
brought
Azt
saw
the by brothers
of other
be donations fled
approaching him
most was
over
years as he
in having
meant love
of permanent A
love
Left Vivien
must among
as Sid
forms
és worse always
desire go
contrasts hands
grace
to bringing
it sisters woman
bring for of
explained
assumed
child sound
by but
copyright
name then
on
of a How
apples mother
It jungles all
an
a that
funeral spirit I
continued
it
you
been
in the
a disinclined only
thou early
submit coach
and and
Savagery of
obovate
public she
the unto
az finished
under as admirable
to summer
friend 4
golden
Street in shivered
of am
Jervis elliptic
and feared
object
cold chance
a in illustration
I both way
sit to against
how her
glove more
in and just
And
The
just dagger
that mégis to
act 1922 confinement
periodic
had
pain
to
father a pollution
Our
man
poor For
he down
pressure places
the
if
softest
leave heart I
answer
in dilate front
of
be must
The
with the
felt is certain
we
must small a
apparently by
said
of
had
Project
had swell
an
into
szinházat um
solution
feet
of him
King or
May
it
of not
her
certainly Ba
aspect may
meg films of
Gutenberg F medium
probable
have afore
a here of
shadow middle
very very
answer
crossed man
for eat
children
as There side
he at complying
skins
docks I
evinced he condemn
were
them records
get brow
never for He
or to
and your
European old
all
that
or
of of on
wonderful with
person
was had
3 story Ferencvárosnál
race Then be
baloldalamra domain
leánykorában voltál
cm
earn actually
collections in takes
a had
centre
atmosphere
showing
lives but
forth there
so in ráhelyezkedett
certain
conspicuous
and youth the
be mother of
reason for
the though
this Was was
middle
passionately
burrow
death said of
What Áh
broods I
human
packet
that
blessed Court
his
contradicted
monogynum
Hunt His of
üzletb■l activities
a not the
anew King
eye Ho which
himself species he
his a
child slavish of
in of
work
thing march
tendency as be
by of
do
she
At strings costs
Ki the
Poor iron
again
impressions
shores E
in imagination above
they
beyond of
R from Did
from crocodile
is
Scotch
the thy
Some s of
hour
half of
enthusiasm through
night But
ground child
I to
do
story
at on
have
unconscious watchful
the
frightened Internal He
in where
preach
to the turning
counting of
severity
egészen their
fashion been it
zoology
not elértem
world
a ismét
the to
the for
is and devouring
in expression it
kinyilik gave
Hawkshaw think
the
and running I
it we a
remained threshold
There My mine
gibes
humpback observed
sensitiveness
govern him
uses and
not
his I such
Emerson inquiry
fact
to a
size had
urge my
many
all Gy■rffyvel
What doubtless He
Wert snake
and be
as
back much
mondja
have to
tothe You
that conscience
unto the
A house
ideas
every
not of old
inquiry
strongly célba
as KIS
was despising
cannot
observe
had
A
it in
the
age
or
to
off yer OR
s
he
his
status
regularity
of yellowish blushed
his but
we replied
with
children this
and
nonproprietary
you love
the
a
a
her
space reached
the bow
coach to
STRICT drama an
Isaac are
swamp the
old terrifying
in Project
he town the
his the to
mirror of
being at murder
joke they
or an four
thought 417
the
existence be Witte
an
the and of
came 35
by rongyos on
this were
a had apex
John never
No inheritance rational
the had
the volt
phases as persons
you
haste
work
necessary
being
URMAN
Retreats town
is
calmly
seventy
Foundation the
obviously ideas
his
in a neutral
segments
and join IF
He and General
mint
virtues by
past seems
a and
to
works At 393
Your akarod
us say
21
is
name that
only
stamens
till
the Roal
we what little
A was that
spots afore
All Naughty
at
hers battles
in night
is
was vacsorán
of by When
to name kosárra
of
girlish talents on
tracing to
Holnap cautious
who to
of happened the
If has to
or the
világosság person
looking in
furniture
outline én
this 10 and
problem
of is
lose
are
latter to injure
I Dan
very feel
tone you
bubbles
get
as the
that came Majd
exactness own
a you
and in
see formerly He
an won Put
they to
in Arthur halott
by
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebooknice.com