CoreDataUtilityTutorial.pdf

(245 KB) Pobierz
Core Data Utility Tutorial
CoreDataUtilityTutorial
DataManagement
2010-09-19
695673700.002.png
AppleInc.
©2005,2010AppleInc.
Allrightsreserved.
exclusionmaynotapplytoyou.Thiswarrantygives
youspecificlegalrights,andyoumayalsohave
otherrightswhichvaryfromstatetostate.
Nopartofthispublicationmaybereproduced,
storedinaretrievalsystem,ortransmitted,in
anyformorbyanymeans,mechanical,
electronic,photocopying,recording,or
otherwise,withoutpriorwrittenpermissionof
AppleInc.,withthefollowingexceptions:Any
personisherebyauthorizedtostore
documentationonasinglecomputerfor
personaluseonlyandtoprintcopiesof
documentationforpersonaluseprovidedthat
thedocumentationcontainsApple’scopyright
notice.
TheApplelogoisatrademarkofAppleInc.
Nolicenses,expressorimplied,aregranted
withrespecttoanyofthetechnologydescribed
inthisdocument.Appleretainsallintellectual
propertyrightsassociatedwiththetechnology
describedinthisdocument.Thisdocumentis
intendedtoassistapplicationdevelopersto
developapplicationsonlyforApple-labeled
computers.
AppleInc.
1InfiniteLoop
Cupertino,CA95014
408-996-1010
Apple,theApplelogo,Cocoa,CocoaTouch,
iPhone,Mac,MacOS,Objective-C,andXcode
aretrademarksofAppleInc.,registeredinthe
UnitedStatesandothercountries.
IOSisatrademarkorregisteredtrademarkof
CiscointheU.S.andothercountriesandisused
underlicense.
EventhoughApplehasreviewedthisdocument,
APPLEMAKESNOWARRANTYORREPRESENTATION,
EITHEREXPRESSORIMPLIED,WITHRESPECTTO
THISDOCUMENT,ITSQUALITY,ACCURACY,
MERCHANTABILITY,ORFITNESSFORAPARTICULAR
PURPOSE.ASARESULT,THISDOCUMENTIS
PROVIDED“ASIS,”ANDYOU,THEREADER,ARE
ASSUMINGTHEENTIRERISKASTOITSQUALITY
ANDACCURACY.
INNOEVENTWILLAPPLEBELIABLEFORDIRECT,
INDIRECT,SPECIAL,INCIDENTAL,OR
CONSEQUENTIALDAMAGESRESULTINGFROMANY
DEFECTORINACCURACYINTHISDOCUMENT,even
ifadvisedofthepossibilityofsuchdamages.
THEWARRANTYANDREMEDIESSETFORTHABOVE
AREEXCLUSIVEANDINLIEUOFALLOTHERS,ORAL
ORWRITTEN,EXPRESSORIMPLIED.NoApple
dealer,agent,oremployeeisauthorizedtomake
anymodification,extension,oradditiontothis
warranty.
Somestatesdonotallowtheexclusionorlimitation
ofimpliedwarrantiesorliabilityforincidentalor
consequentialdamages,sotheabovelimitationor
695673700.003.png
Contents
Introduction IntroductiontoCoreDataUtilityTutorial 7
WhoShouldReadThisDocument 7
OrganizationofThisDocument 7
SeeAlso 8
Chapter1 OverviewoftheTutorial 9
TaskGoal 9
Chapter2 CreatingtheProject 11
CreateaNewProject 11
Createtheproject 11
LinktheCoreDataframework 11
AdoptGarbageCollection 12
WhatHappened? 12
Chapter3 CreatingtheManagedObjectModel 13
SpecifyingtheEntity 13
CreatetheManagedObjectModel 13
CreatetheModelInstance 13
CreatetheEntity 14
AddtheAttributes 14
AddaLocalizationDictionary 15
InstantiateaManagedObjectModel 16
BuildandTest 16
CompleteListing 16
Chapter4 TheApplicationLogDirectory 19
TheapplicationLogDirectoryFunction 19
UpdatethemainFunction 20
BuildandTest 20
Chapter5 CreatingtheCoreDataStack 21
Overview 21
ThemanagedObjectContextFunction 21
CreatetheContextInstance 21
SetupthePersistentStoreCoordinatorandStore 22
2010-09-19 | © 2005, 2010 Apple Inc. All Rights Reserved.
3
695673700.004.png
CONTENTS
InstantiateaManagedObjectContext 22
BuildandTest 23
CompleteListing 23
Chapter6 TheCustomManagedObjectClass 25
ImplementingtheManagedObjectSubclass 25
CreatetheClassFiles 25
ImplementtheAccessorMethods 26
DealingWithnilValues 26
ImplementtheInitializer 27
CreateanInstanceoftheRunEntity 27
BuildandTest 28
CompleteListings 28
TheRunClass 28
Themain()Function 29
Chapter7 ListingPreviousRuns 31
FetchingRunObjects 31
CreateandExecutetheFetchRequest 31
DisplaytheResults 31
BuildandTest 32
Chapter8 CompleteSourceListings 33
main 33
TheRunClass 37
DocumentRevisionHistory 39
4
2010-09-19 | © 2005, 2010 Apple Inc. All Rights Reserved.
695673700.005.png
TablesandListings
Chapter3 CreatingtheManagedObjectModel 13
Table3-1 AttributesfortheRunentity 13
Listing3-1 Completelistingofthe managedObjectModel function 16
Chapter5 CreatingtheCoreDataStack 21
Listing5-1 Completelistingofthe managedObjectContext function 23
Chapter6 TheCustomManagedObjectClass 25
Listing6-1 CompletelistingofthedeclarationandimplementationoftheRunclass 28
Listing6-2 Listingofthe main function 29
Chapter8 CompleteSourceListings 33
Listing8-1 Completelistingofthe main sourcefile 33
Listing8-2 ListingofthedeclarationoftheRunclass 37
Listing8-3 ListingoftheimplementationoftheRunclass 37
2010-09-19 | © 2005, 2010 Apple Inc. All Rights Reserved.
5
695673700.001.png
Zgłoś jeśli naruszono regulamin