ptg5934432FromtheLibraryofLeeBogdanoffptg5934432PraiseforCocoaDesignPatterns“Thislong-neededbookisagreatresourceforCocoanewcomersandveteranswhowanttogetthewhybehindthewhat.Thelistofpatternsgiveshistoricalperspectiveandanswersmanydeveloperquestionsandthelastthreechapters—coveringCoreData,AppKit,andBindings—areamust-read;theyrevealinsightsthatmightotherwiserequirehoursofdiscussionwithAppleengineersoraccesstosourcecode.”—TimBurks,SoftwareDeveloperandCreatoroftheNuProgrammingLanguage,www.programming.nu“ThisbookisacomprehensiveandauthoritativetreatmentofdesignpatternsandtheirpracticalapplicationsinCocoaprojects.IrecommendthisbooktoanyonewhowantstoadvancefromintermediatetoexpertproficiencyasaMacintoshdeveloper.”—JohnC.Randolph,VicePresidentEngineering,StealthImaging,Inc.“CocoaDesignPatternsisafantasticbookthatwillshowyoutheinsandoutsofsoftwaredesignpatterns,howCocoamakesuseofthem,andhowtoapplythemtoyourownapplicationsforbetter,morerobust,andmoremaintainablesoftware.”—AugustTrometer,OwnerofFoggyNogginSoftware“CocoaDesignPatternsissuperb!Itishighlyreadable,thoroughlyenjoyable,andfilledtothebrimwithwisdomthatwillmakeyouamoreefficientandeffectiveprogrammer.Theauthorsutilizeaconsistentandself-containedapproachtoeachchapter,makingiteasytoreturntouseasareference.However,thematerialissointerestingandvitaltoCocoaprogrammersthatyou’llwanttoreaditfromcovertocover.”—DavidMandell,IndependentDeveloper“ErikandDonald’sbookreallyhelpedmeoutwiththeconceptualsideofprogram-ming.ItcausedmetorealizewhereIwasgoingwronginmycodeandhelpedmesortoutmydesignissues.”—EoinHoulihan“ThisbookisrecommendedforanyprogrammerinterestedinadeeperunderstandingofCocoa.Readingitmighthavehelpedmebecomeabettersoftwareengineerinanyobject-orientedlanguage.I’llkeepithandyasaconstantreferenceandlookforwardtoreadingitagainmorecarefully.”—DarylSpitzerFromtheLibraryofLeeBogdanoffDownloadatWoweBook.Comptg5934432ThispageintentionallyleftblankFromtheLibraryofLeeBogdanoffDownloadatWoweBook.Comptg5934432CocoaDesignPatternsFromtheLibraryofLeeBogdanoffDownloadatWoweBook.Comptg5934432ThispageintentionallyleftblankFromtheLibraryofLeeBogdanoffDownloadatWoweBook.Comptg5934432CocoaDesignPatternsErikM.BuckDonaldA.YacktmanUpperSaddleRiver,NJ•Boston•Indianapolis•SanFranciscoNewYork•Toronto•Montreal•London•Munich•Paris•MadridCapeTown•Sydney•Tokyo•Singapore•MexicoCityFromtheLibraryofLeeBogdanoffDownloadatWoweBook.Comptg5934432Manyofthedesignationsusedbymanufacturersandsellerstodistinguishtheirproductsareclaimedastrademarks.Wherethosedesignationsappearinthisbook,andthepublish-erwasawareofatrademarkclaim,thedesignationshavebeenprintedwithinitialcapitallettersorinallcapitals.Theauthorsandpublisherhavetakencareinthepreparationofthisbookbutmakenoexpressedorimpliedwarrantyofanykindandassumenoresponsibilityforerrorsoromis-sions.Noliabilityisassumedforincidentalorconsequentialdamagesinconnectionwithorarisingoutoftheuseoftheinformationorprogramscontainedherein.Thepublisheroffersexcellentdiscountsonthisbookwhenorderedinquantityforbulkpur-chasesorspecialsales,whichmayincludeelectronicversionsand/orcustomcoversandcontentparticulartoyourbusiness,traininggoals,marketingfocus,andbrandinginterests.Formoreinformation,pleasecontactU.S.CorporateandGovernmentSales(800)382-3419corpsales@pearsontechgroup.comForsalesoutsidetheUnitedStates,pleasecontactInternationalSalesinternational@pearson.comVisitusontheWeb:informit.com/awLibraryofCongressCataloging-in-PublicationData:Buck,ErikM.Cocoadesignpatterns/ErikM.Buck,DonaldA.Yacktman.p.cm.Includesbibliographicalreferencesandindex.ISBN978-0-321-53502-3(pbk.:alk.paper)1.Cocoa(Applicationdevelopmentenviron-ment)2.Object-orientedprogramming(Computerscience)3.Softwarepatterns.4.MacOS.I.Yacktman,DonaldA.II.Title.QA76.64.B822009005.26’8—dc222009023288Copyright©2010PearsonEducation,Inc.Allrightsreserved.PrintedintheUnitedStatesofAmerica.Thispublicationisprotectedbycopyright,andpermissionmustbeobtainedfromthepublisherpriortoanyprohibitedrepro-duction,storageinaretrievalsystem,ortransmissioninanyformorbyanymeans,elec-tronic,mechanical,photocopying,recording,orlikewise.Forinformationregardingpermis-sions,writeto:PearsonEducation,Inc.RightsandContractsDepartment501BoylstonStreet,Suite900Boston,MA02116Fax(617)671-3447ISBN-13:978-0-321-53502-3ISBN-10:0-321-53502-2TextprintedintheUnitedStatesonrecycledpaperatR.R.DonnelleyinCrawfordsville,Indiana.FirstprintingSeptember2009Editor-in-ChiefKarenGettmanAcquisitionsEditorChuckToporekDevelopmentEditorSheriCainManagingEditorKristyHartProjectEditorJovanaSanNicolas-ShirleyCopyEditorLanguageLogistics,LLCIndexerRebeccaSalernoProofreaderApostropheEditingServicesPublishingCoordinatorRomnyFrenchCoverDesignerGaryAdairCompositorJakeMcFarlandFromtheLibraryofLeeBogdanoffDownloadatWoweBook.Comptg5934432❖Tomybelovedwife,Michelle,whomakesmylifeandeveryaccomplishmentpossible,andtomychildren,Joshua,Emma,andJacob,fortheirtirelesssupportandunderstanding.—ErikM.Buck❖DedicatedtomywifeMarcieforherpatienceandsupportandmyboys,JosephandWilliam,fortheirneve