AboutThiseBook
ePUBisanopen,industrystandardformatforeBooks.However,supportofePUBanditsmanyfeaturesvariesacrossreadingdevicesandapplications.Useyourdeviceorappsettingstocustomizethepresentationtoyourliking.Settingsthatyoucancustomizeoftenincludefont,fontsize,singleordoublecolumn,landscapeorportraitmode,andfiguresthatyoucanclickortaptoenlarge.Foradditionalinformationaboutthesettingsand
featuresonyourreadingdeviceorapp,visitthedevicemanufacturersWebsite.
Manytitlesinclude
programmingcodeor
configurationexamples.Tooptimizethepresentationoftheseelements,viewtheeBookinsingle-column,landscapemodeandadjustthefontsizetothesmallestsetting.Inadditionto
presentingcodeand
configurationsinthe
reflowabletextformat,wehaveincludedimagesofthecodethatmimicthe
presentationfoundintheprintbook;therefore,wherethereflowableformatmaycompromisethepresentationofthecodelisting,youwillseeaClickheretoviewcodeimagelink.Clickthelinktoviewtheprint-fidelitycodeimage.Toreturntothepreviouspageviewed,clicktheBackbuttononyourdeviceorapp.
TheGourmetiOSDevelopersCookbook
EvenMoreRecipesforBetteriOSAppDevelopmentEricaSadun
NewYorkBostonIndianapolisSanFranciscoTorontoMontrealLondon
MunichParisMadridCapeTownSydneyTokyo
SingaporeMexicoCityManyofthedesignations
usedbymanufacturersandsellerstodistinguishtheirproductsareclaimedastrademarks.Wherethosedesignationsappearinthisbook,andthepublisherwasawareofatrademarkclaim,thedesignationshavebeenprintedwithinitialcapitallettersorinallcapitals.
TheGourmetiOS
DevelopersCookbook:EvenMoreRecipesforBetteriOSAppDevelopmentisan
independentpublicationandhasnotbeenauthorized,sponsored,orotherwiseapprovedbyAppleInc.
Apple,theApplelogo,AppleTV,AppleWatch,Cocoa,CocoaTouch,eMac,
FaceTime,Finder,iBook,iBooks,iCal,Instruments,iPad,iPadAir,iPadmini,iPhone,iPhoto,iTunes,theiTuneslogo,iWork,
Keychain,Launchpad,Lightning,LocalTalk,Mac,theMaclogo,MacApp,MacBook,MacBookAir,MacBookPro,MacDNS,Macintosh,MacOS,MacPro,MacTCP,theMadeforiPadlogo,theMadeforiPhonelogo,theMadeforiPodlogo,Metal,theMetallogo,theMonacocomputerfont,Multi-Touch,theNewYorkcomputerfont,
Objective-C,OpenCL,OSX,Passbook,Pixlet,PowerBook,PowerMac,Quartz,
QuickDraw,QuickTime,theQuickTimelogo,Retina,Safari,theSandcomputerfont,Shake,Siri,theSkiacomputerfont,Swift,theSwiftLogo,theTextile
computerfont,TouchID,TrueType,WebObjects,
WebScript,andXcodearetrademarksofApple,Inc.,registeredintheUnitedStatesandothercountries.OpenGLandthelogoareregisteredtrademarksofSilicon
Graphics,Inc.TheYouTubelogoisatrademarkof
Google,Inc.Intel,IntelCore,andXeonaretrademarksofIntelCorp.intheUnitedStatesandothercountries.
Theauthorandpublisherhavetakencareinthe
preparationofthisbook,butmakenoexpressedorimpliedwarrantyofanykindandassumenoresponsibilityforerrorsoromissions.No
liabilityisassumedfor
incidentalorconsequentialdamagesinconnectionwithorarisingoutoftheuseoftheinformationorprogramscontainedherein.
Forinformationaboutbuyingthistitleinbulkquantities,orforspecialsalesopportunities(whichmayinclude
electronicversions;customcoverdesigns;andcontentparticulartoyourbusiness,traininggoals,marketingfocus,orbrandinginterests),pleasecontactourcorporatesalesdepartmentat
corpsales@pearsoned.com or(800)382-3419.
Forgovernmentsales
inquiries,pleasecontact
governmentsales@pearsoned.com
ForquestionsaboutsalesoutsidetheU.S.,please
contact
international@pearsoned.com .
VisitusontheWeb: informit.com/aw LibraryofCongressControlNumber:2015935369Copyright2015PearsonEducation,Inc.
Allrightsreserved.PrintedintheUnitedStatesofAmerica.Thispublicationisprotectedbycopyright,andpermissionmustbeobtainedfromthepublisherpriortoany
prohibitedreproduction,storageinaretrievalsystem,ortransmissioninanyformorbyanymeans,electronic,mechanical,photocopying,recording,orlikewise.Toobtainpermissiontousematerialfromthiswork,pleasesubmitawritten
requesttoPearsonEducation,Inc.,PermissionsDepartment,200OldTappanRoad,OldTappan,NewJersey07675,oryoumayfaxyourrequestto(201)236-3290.
ISBN-13:978-0-13-408622-4ISBN-10:0-13-408622-8
TextprintedintheUnitedStatesonrecycledpaperatRRDonnelleyin
Crawfordsville,Indiana.
Firstprinting:May2015 Editor-in-Chief MarkTaub SeniorAcquisitionsEditor TrinaMacDonald SeniorDevelopmentEditor ChrisZahn ManagingEditor KristyHart SeniorProjectEditor BetsyGratner CopyEditor KittyWilson Indexer TimWright Proofreader SarahKearns
TechnicalReviewers MarkGranoff
MikeGreiner
RichWardwell
EditorialAssistant OliviaBasegio CoverDesigner ChutiPrasertsith Compositor NonieRatcliff
DedicatedwithgreataffectiontoChrisZahn:editor,enabler,andwonderfulperson.
Contents
Preface
1MediaSpeech
OtherOptions
DelegateCallbacksDictation
CreatingBarcodesFilterParameters
BuildingCodes
ReadingBarcodes
ListeningforMetadataObjects
RespondingtoMetadataExtractingBounds
EnhancingRecognitionDetectingFaces
BuildingAVFoundationMovies
CreatingaPixelBufferDrawingintothePixelBuffer
ExpressiveDrawingBuildingMoviesfromFrames
AddingImagestoMoviesWrap-up
2DynamicTypographyTypeSizeandUserNeeds
HowDynamicTypeWorks
ListeningforType
Updates
HandlingDynamicTypewithAttributes
ScanningforTextStyleRanges
ApplyingTextStyleRanges
Attribute-ReadyDynamicElements
CustomFontsFacesDynamicTextViewsCustomSizing
FontDescriptors
DescriptorChallengesFontswithMultiple
Variations
UsingStringAttributestoModifyFonts
DynamicTypeGotchasWrap-up
3TextKitCreatingComplexTextLayouts
Glyphs
TextStorage
LayoutManagers
TextContainers
AdaptiveFlow
Insets
ExclusionPaths
BoundingRectangles
UsingTextKittoAddTouchtoLabels
EstablishingTextKitSynchronizing
TranslatingCoordinatesGlyphsandCharactersCheckingforLinks
AddingVisualFeedback
DraggableExclusion
Zones
BuildingPDFswithTextKit
PrintingTextViewDataPrintingPDFData
Wrap-up
4AttributedStringsandDocumentContainersClassEnhancements
StringAttachments
BuildingAttributedStringsfromHTML
DocumentType
Dictionaries
ConvertingHTML
SourcetoAttributedStrings
ConvertingAttributedStringstoDocumentRepresentations
GeneratingHTMLfromAttributedStrings
MarkupInitializationRTFandRTFD
TheRTFDContainer
InitializingAttributedStringsfromaFile
ConvertingRTFDTexttoData
WritingRTFD
ContainersfromDataInspectingAttributesEstablishingDocumentAttributes
EnhancingAttributed
Strings
ReturningCopieswithNewAttributes
AdjustingAttributesExtendingMutableAttributedStrings
TextRanges
CalculatingPositionsPositionGeometry
UpdatingSelectionPoints
HardwareKeySupportWrap-up
5Animation KeyframeAnimationBuildingPhysicswithKeyframes
BlockingAnimators
UIKitSpring-Based
Animations
PracticalUsesforSpringAnimations
SystemAnimations
MotionEffects
BuildingPlanes
ShadowEffects
CustomTransition
Animations
Delegation
BuildingTransitioningObjects
ImplicitAnimations
BuildinganAnimationReadyLayer
BuildingaViewAroundaLayer
Timing
CoordinatingAnimationsBuildingImplicit
CompletionBlocksAnimatingCustomProperties
InterceptingUpdatesDrawingPropertiesWrap-up
6DynamicAnimatorsPhysics-BasedBehaviorsBuildingDynamicsDetectingPauses
CreatingaFrame
WatchingDynamicBehavior
ImplementingSnapZonesLeveragingReal-WorldPhysics
ConnectingaGravityBehaviortoDeviceAcceleration
CreatingBoundariesEnhancingView
Dynamics
CustomBehaviors
CreatingCustom