Sams Teach Yourself Ios®9 Application Development in 24 Hours
Total Page:16
File Type:pdf, Size:1020Kb
John Ray SamsTeachYourself iOS®9 Application Development in Hours24 800 East 96th Street, Indianapolis, Indiana, 46240 USA Sams Teach Yourself iOS9® Application Development in 24 Hours Editor-in-Chief Copyright © 2016 by Pearson Education, Inc. Greg Wiegand All rights reserved. Printed in the United States of America. This publication is protected by Acquisitions Editor copyright, and permission must be obtained from the publisher prior to any prohibited repro- Laura Norman duction, storage in a retrieval system, or transmission in any form or by any means, electron- ic, mechanical, photocopying, recording, or likewise. For information regarding permissions, Development Editor request forms, and the appropriate contacts within the Pearson Education Global Rights & Keith Cline Permissions Department, please visit www.pearsoned.com/permissions/ . No patent liability is assumed with respect to the use of the information contained herein. Although every pre- Managing Editor caution has been taken in the preparation of this book, the publisher and author assume no Kristy Hart responsibility for errors or omissions. Nor is any liability assumed for damages resulting from Senior Project Editor the use of the information contained herein. Lori Lyons ISBN-13: 978-0-672-33767-3 ISBN-10: 0-672-33767-3 Copy Editor Keith Cline Library of Congress Control Number: 2015917495 First Printing February 2016 Indexer Publishing Works Trademarks All terms mentioned in this book that are known to be trademarks or service marks have been Proofreader appropriately capitalized. Sams Publishing cannot attest to the accuracy of this information. Laura Hernandez Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark. Technical Editor Anne Groves Warning and Disclaimer Every effort has been made to make this book as complete and as accurate as possible, but Editorial Assistant no warranty or fitness is implied. The information provided is on an “as is” basis. The author Sandra Fugate and the publisher shall have neither liability nor responsibility to any person or entity with respect to any loss or damages arising from the information contained in this book. Cover Designer Mark Shirar Special Sales For information about buying this title in bulk quantities, or for special sales opportunities Compositor (which may include electronic versions; custom cover designs; and content particular to your Nonie Ratcliff business, training goals, marketing focus, or branding interests), please contact our corporate sales department at [email protected] or (800) 382-3419. For government sales inquiries, please contact [email protected] . For questions about sales outside the U.S., please contact [email protected] . Contents at a Glance Introduction .................................................................................... 1 HOUR 1 Preparing Your System and iDevice for Development .......................... 5 2 Introduction to Xcode and the iOS Simulator ................................... 29 3 Discovering Swift and the iOS Playground ....................................... 73 4 Inside Cocoa Touch...................................................................... 123 5 Exploring Interface Builder ........................................................... 1 55 6 Model-View-Controller Application Design ..................................... 1 93 7 Working with Text, Keyboards, and Buttons ................................... 223 8 Handling Images, Animation, Sliders, and Steppers ........................ 259 9 Using Advanced Interface Objects and Views ................................. 291 10 Getting the User’s Attention .......................................................... 329 11 Implementing Multiple Scenes and Popovers .................................. 361 12 Making Choices with Toolbars and Pickers ..................................... 413 13 Advanced Storyboards Using Navigation and Tab Bar Controllers ............................................................................ 457 14 Navigating Information Using Table Views and Split View Controllers .................................................................................. 497 15 Reading and Writing Application Data ......................................... 539 16 Building Responsive User Interfaces ............................................... 585 17 Using Advanced Touches and Gestures .......................................... 627 18 Sensing Orientation and Motion ................................................... 663 19 Working with Rich Media ............................................................. 693 20 Interacting with Other iOS Services ............................................... 743 21 Implementing Location Services .................................................... 781 22 Building Background-Ready Applications ...................................... 813 23 Universal Applications and Size Classes ......................................... 853 24 Application Tracing, Monitoring, and Debugging........................... 877 Index .......................................................................................... 903 A Introducing Xcode Source Control .............................................Online Note: Appendix A is a bonus online chapter. To access it, go to www.informit.com/title/9780672337673 and click the Downloads tab. Table of Contents Introduction 1 Who Can Become an iOS Developer? ........................................................... 2 Who Should Use This Book? ........................................................................ 2 What Is (and Isn’t) in This Book? ................................................................ 3 Hour 1: Preparing Your System and iDevice for Development 5 Welcome to the iOS Platform ...................................................................... 5 Becoming an iOS Developer ...................................................................... 10 Running an iOS App ................................................................................ 15 Developer Technology Overview ................................................................ 22 Further Exploration .................................................................................. 24 Summary ................................................................................................ 24 Q&A ....................................................................................................... 24 Workshop ................................................................................................ 25 Activities ................................................................................................. 27 Hour 2: Introduction to Xcode and the iOS Simulator 29 Using Xcode ............................................................................................ 29 Using the iOS Simulator ........................................................................... 61 Further Exploration .................................................................................. 69 Summary ................................................................................................ 69 Q&A ....................................................................................................... 69 Workshop ................................................................................................ 70 Activities ................................................................................................. 72 Hour 3: Discovering Swift and the iOS Playground 73 Object-Oriented Programming and Swift .................................................... 73 The Terminology of Object-Oriented Development ...................................... 75 Exploring the Swift File Structure ............................................................... 78 Swift Programming Basics ......................................................................... 84 Memory Management and Automatic Reference Counting ........................ 110 Contents v Introducing the iOS Playground .............................................................. 111 Further Exploration ................................................................................ 118 Summary .............................................................................................. 119 Q&A ..................................................................................................... 119 Workshop .............................................................................................. 120 Activities ............................................................................................... 122 Hour 4: Inside Cocoa Touch 123 What Is Cocoa Touch? ............................................................................ 123 Exploring the iOS Technology Layers ....................................................... 125 Tracing the iOS Application Life Cycle ..................................................... 132 Cocoa Fundamentals .............................................................................. 134 Exploring the iOS Frameworks with Xcode ............................................... 142 Further Exploration ................................................................................ 149 Summary .............................................................................................. 149 Q&A ....................................................................................................