beginning ios programming for dummies

457 875 1
beginning ios programming for dummies

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Rajiv Ramnath, PhD is Associate Professor of Practice in computer science and engineering and Director of Practice at the Collaborative for Enterprise Transformation and Innovation at The Ohio State University. Before that, he worked in industry, leading research and commercial product development . Cover Image: ©iStockphoto.com/iLexx Go to Dummies.com ® for videos, step-by-step Photos, how-to articles, or to shop! $29.99 USA / $35.99 CAN / £21.99 UK 9 781118 799277 52999 ISBN:978-1-118-79927-7 Open the book and find: •The basics of object-oriented programming •How to use patterns and frameworks •Details on setting up the Xcode Development Environment •Examples to help you do object-oriented iOS app design •How to make your apps fast and responsive •Information on designing user-friendly apps •How to publish to the App Store •Ten developer resources for iOS Programming Languages/iOS Get coding today with this useful guide to creating iOS apps Apple’s iOS is everywhere, thanks to the iPhone, iPad, and other devices. If you’ve always wanted to be an iOS programming rock star, this great resource is the guide for you. Discover iOS programming, including how to get your apps into Apple’s famous App Store and the best way to make applications that users will be clamoring to download. •iOSiseverywhere—getstartedwithcreatingappsforthishighly popularmobileoperatingsystem •Meetingthemethodsandplatforms—takeyourobject-oriented programmingtothenextlevelwiththeXcodeDevelopment Environment •MakingyouriOSappsgreat—makeuser-friendlyappsthatare fast,responsive,complete,robust,reliable,andsecure •Connectingyourapps—publishyourappsintheAppStore andbecomeaniOSprogrammingstar •Studyup—usealonglistofresourcestofindoutmoreabout object-orientedandiOSprogramming BeginningiOSProgramming Ramnath Rajiv Ramnath, PhD Author of Android 3 SDK Programming For Dummies Learnto: •Program in the iOS environment using Xcode ® and Cocoa® frameworks •Create simple interfaces •Work with libraries, storyboards, arrays, structures, functions, and pointers •Use simulators for testing and development Beginning iOSProgramming Making  Everything  E asier! ™ www.it-ebooks.info Start with FREE Cheat Sheets Cheat Sheets include  •Checklists  •Charts  •CommonInstructions  •AndOtherGoodStuff! Get Smart at Dummies.com Dummies.com makes your life easier with 1,000s of answers on everything from removing wallpaper to using the latest version of Windows. Check out our  •Videos  •IllustratedArticles  •Step-by-StepInstructions Plus, each month you can win valuable prizes by entering our Dummies.com sweepstakes. * Want a weekly dose of Dummies? Sign up for Newsletters on  •DigitalPhotography  •MicrosoftWindows&Office  •PersonalFinance&Investing  •Health&Wellness  •Computing,iPods&CellPhones  •eBay  •Internet  •Food,Home&Garden Find out “HOW” at Dummies.com *Sweepstakes not currently available in all countries; visit Dummies.com for official rules. Get More and Do More at Dummies.com ® To access the Cheat Sheet created specifically for this book, go to www.dummies.com/cheatsheet/beginningiosprogramming www.it-ebooks.info by Rajiv Ramnath and Cheyney Long Beginning iOS Programming www.it-ebooks.info Beginning iOS Programming For Dummies ® Published by: John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030-5774, www.wiley.com Copyright © 2014 by John Wiley & Sons, Inc., Hoboken, New Jersey Media and software compilation copyright © 2014 by John Wiley & Sons, Inc. All rights reserved. Published simultaneously in Canada No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without the prior written permission of the Publisher. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions. Trademarks: Wiley, For Dummies, the Dummies Man logo, Dummies.com, Making Everything Easier, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and may not be used without written permission. All other trademarks are the property of their respective owners. John Wiley & Sons, Inc. is not associated with any product or vendor mentioned in this book. LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZATION OR WEBSITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OF FURTHER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATION THE ORGANIZATION OR WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE. FURTHER, READERS SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ. For general information on our other products and services, please contact our Customer Care Department within the U.S. at 877-762-2974, outside the U.S. at 317-572-3993, or fax 317-572-4002. For technical support, please visit www.wiley.com/techsupport. Wiley publishes in a variety of print and electronic formats and by print-on-demand. Some material included with standard print versions of this book may not be included in e-books or in print-on-demand. If this book refers to media such as a CD or DVD that is not included in the version you purchased, you may download this material at http://booksupport.wiley.com. For more information about Wiley products, visit www.wiley.com. Library of Congress Control Number: 2013954213 ISBN 978-1-118-79927 7 (pbk); ISBN 978-1-118-79931-4 (ebk); ISBN 978-1-118-79932-1 (ebk) Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 www.it-ebooks.info Contents at a Glance Introduction 1 Part I: Getting Started with iOS Programming 5 Chapter 1: Entering Mobile Application Development 7 Chapter 2: Object-Oriented Design Principles 25 Chapter 3: Effectively Using Objective-C 55 Part II: Meeting the Methods and Platforms 89 Chapter 4: Patterns and Frameworks 91 Chapter 5: Setting Up to Develop iOS Apps 113 Chapter 6: Developing an App on iOS 135 Chapter 7: Illustrating Object-Oriented iOS App Design 173 Part III: Making Your iOS Apps Fit for Consumption 207 Chapter 8: Effectively Using Xcode 209 Chapter 9: Developing Your App’s User Interface 249 Chapter 10: Making Applications Fast and Responsive 277 Chapter 11: Making Your App Reliable andSecure 293 Part IV: Connecting Your Apps 327 Chapter 12: Channeling the World Into Your Device 329 Chapter 13: Harnessing iOS Device Capabilities 345 Chapter 14: Publishing to the App Store 375 Part V: The Part of Tens 399 Chapter 15: Ten Resources for Object-Oriented Development 401 Chapter 16: Ten Developer Resources for iOS 413 Index 423 www.it-ebooks.info www.it-ebooks.info Table of Contents Introduction 1 About This Book 1 Foolish Assumptions 3 Icons Used inThis Book 3 Beyond theBook 4 Part I: Getting Started with iOS Programming 5 Chapter 1: Entering Mobile Application Development 7 Apps fora Mobile Platform 7 iOS Benefits 10 iOS App Development Essentials 12 Devices 12 Application development technologies 13 Xcode 18 The Application Model 19 Understanding thelifecycle ofan iOS app 20 Understanding thestructure ofan iOS app 22 Object-Orientation Concepts 23 Chapter 2: Object-Oriented Design Principles 25 Basic Object-Oriented Concepts 25 Designing programs 26 Structural and behavioral concepts inOO 36 Principles ofObject-Orientation 38 Coupling 39 Cohesion 40 Designing anObject-Oriented Application 40 Advanced OO Techniques 42 Delayed binding 42 Delegation 43 Design patterns 43 Inversion ofcontrol and software frameworks 44 The Application Development Lifecycle 45 Software development lifecycle processes 46 The phases and stages ofa software development lifecycle (SDLC) 47 The guiding principles ofSDLC methodologies 50 Customizing anSDLC methodology 51 www.it-ebooks.info Beginning iOS Programming For Dummies vi Chapter 3: Effectively Using Objective-C 55 Examining anObjective-C Program 55 Defining Classes 58 Declaring instance variables 61 Declaring methods 62 Using forward references 64 Implementing classes 65 Using Classes, Objects, Methods, and Variables 66 Invoking methods 66 Creating objects 67 Using all thelanguage features 69 Using introspection and dynamic invocation 80 Managing Memory 82 Handling Exceptions 84 Organizing Program Files 85 Analyzing Objective-C’s Object-Orientation Capabilities 86 Part II: Meeting the Methods and Platforms 89 Chapter 4: Patterns and Frameworks 91 Common Patterns ofOO Design 91 Seeing basic design patterns 92 Understanding theModel-View-Controller 98 Making model objects persistent 99 Avoiding anti-patterns 105 Applying patterns toapplication design 106 Understanding Frameworks 106 Inversion ofcontrol 106 Basic concepts 107 Flow ofcontrol 109 Chapter 5: Setting Up to Develop iOS Apps 113 Becoming aniOS Developer 113 Installing, Verifying, and Understanding theXcode Development Environment 119 Installing Xcode 119 Verifying thedevelopment environment 121 Understanding theelements ofan Xcodeworkspace 127 Importing and Running theTic-Tac-Toe Sample Program 128 Importing Tic-Tac-Toe and running it onthe simulator 128 Deploying anApp onan iOS device 130 www.it-ebooks.info vii Table of Contents Chapter 6: Developing an App on iOS 135 Dissecting aniOS App 135 Understanding anApp’s Lifecycle 138 Interacting withthe App Through Its User Interface 141 Dealing withData 141 Using JSON 142 Saving data using files 145 Moving upto Core Data 149 Accessing theAddress Book 158 Setting options foryour app 160 Sharing data acrossapps 164 Using Other iOS Capabilities ona Device 165 Visiting theApp Templates inXcode 166 Deconstructing theiOS Framework Using OO Principles and Design Patterns 169 Seeing object-oriented concepts and techniques iniOS 169 Seeing patterns iniOS 170 Critiquing theiOS framework from the perspective of OO principles 171 Chapter 7: Illustrating Object-Oriented iOS App Design 173 Customizing anSDLC foriOS App Development 173 Developing Use Cases 175 Creating theUser Interface 177 Illustrating Object-Oriented Design 180 Classes and responsibilities 181 Collaborators and missing classes and responsibilities 183 Contracts and signatures 186 Implementing anObject-Oriented Design oniOS 188 Implementing themodel 188 Creating storyboards and views 193 Making theapp active 195 Analyzing theOO and Design Principles Used inTic-Tac-Toe 199 Use ofdesign patterns inTic-Tac-Toe 201 Other concepts 204 Part III: Making Your iOS Apps Fit for Consumption 207 Chapter 8: Effectively Using Xcode 209 Xcode and IOS—A Beautiful Friendship 210 Setting upyour app’s project 211 Creating your app’s screen flow 214 www.it-ebooks.info Beginning iOS Programming For Dummies viii Writing your app’s code 222 Managing and maintaining your app’s components 227 Fine-Tuning Your App inXcode 237 Configuring your app 237 Digging intothe Simulator 239 Exploring your iOS device fromXcode 240 Debugging your app 243 Using instruments tocollect data 244 Getting Help 247 Chapter 9: Developing Your App’s User Interface 249 Understanding How User Interfaces Work iniOS 249 Comprehending event-driven programming iniOS 250 Understanding theApplication and theApplication Delegate objects inUI processing 250 Revisiting theModel-View-Controller Design Pattern 253 Understanding theUI Components Available iniOS 256 Interacting withbuttons, text fields, and labels 258 Alerting theuser 262 Selecting items using pickers 264 Showing columnar data using a Table view 266 Going throughthe other views inthe iOS framework 268 Navigating througha stack ofscreens using a Navigation controller 269 Drawing using 2-D Graphics 272 Chapter 10: Making Applications Fast and Responsive 277 Becoming Familiar withNonfunctional Requirements 278 Designing Your App atMultiple Levels 279 Optimizing anApplication’s Performance 280 Using Instrumentation for CodeOptimization 282 Ensuring Responsiveness inYour Apps 287 Ensuring responsiveness byusing threading 288 Other Performance Considerations foriOS Apps 291 Chapter 11: Making Your App Reliable andSecure 293 Making Your App Reliable ThroughTesting 293 Understanding thefundamentals and levels oftesting 294 Understanding thelevels oftesting 294 Using automated testing 297 Adapting toChanges inthe App’sEnvironment 304 Implementing reliability while navigating your app’s lifecycle 304 Dealing withmissing or transient capabilities 309 Considering Security inan iOS App 310 Recognizing theimportance ofsecurity 310 www.it-ebooks.info [...]... pitfall ahead www.it-ebooks.info 3 4 Beginning iOS Programming For Dummies Beyond the Book A lot of extra content that is not in this book is available at www .dummies com Go online to find the following: ✓ Online articles covering additional topics at www .dummies. com/extras/beginningiosprogramming ✓ The Cheat Sheet for this book is at www .dummies. com/cheatsheet/beginningiosprogramming ✓ Updates to this... www .dummies. com/extras/beginningiosprogramming www.it-ebooks.info Part I Getting Started with iOS Programming Visit www .dummies. com for great Dummies content online www.it-ebooks.info In this part . .  ✓ Essential application development guidelines ✓ The application model ✓ Basic design principles ✓ Advanced techniques ✓ Using classes, objects, methods, and variables ✓ Visit www .dummies. com for. .. love Apps for a Mobile Platform This book assumes that you’ve written applications for other platforms, such as desktop or laptop computers or the web You can transfer a lot of this experience to writing applications for mobile devices like cellphones and tablets, including iOS devices www.it-ebooks.info 8 Part I: Getting Started with iOS Programming However, when writing applications for iOS, you need... strong skills in iOS app development iOS Benefits Although many types of smartphones and mobile devices are still on the market today, the battle for market share is now pretty much between iOS and Android The lure of Apple and its wonderful set of innovative devices are what make the iOS platform so popular, and developing on the iOS platform offers you several benefits: ✓ Wide acceptance: iOS has legs — it’s... awarded a patent for NFC-enabled data synching technology For the inside story from Apple, check the link labeled NFC at www .dummies. com/go/iosprogramminglinks Unless you really and truly want to, you’ll never see iOS, the operating system, nor will your program However, you must recognize that it’s there — the iOS framework does certain things in certain ways because it runs on iOS For example, every... generations of iOS devices had even smaller screens (iPhones prior to iOS 5 and iPod Touches prior to the 5th generation all had 3.5-inch displays) Also, Apple TV runs iOS If Apple opens these platforms for app development with the latest iOS versions, the problem of creating universal apps will become even more complicated ✓ Limited storage: iOS devices can store only about one-tenth of the information... and updates: For long URLs, I refer you to the book’s website (for example: "To find out more about windows and views, go to www dummies. com/go/iosprogramminglinks and check out the Windows and Views link in the web resources for this chapter." Also, I will continue to provide updates for the code and post other things you might find useful on the book’s website ✓ Sidebars and technical information:... equivalent iOS application (such as iPhone), you’ll probably quickly understand the iOS programming model and then navigate on to the chapters you’re most interested in Here are some of the conventions you will see in the book: ✓ Code examples: These appear in a fixed-width font so that they stand out, as illustrated here: [self initializeGameSession]; www.it-ebooks.info 2 Beginning iOS Programming For Dummies. .. detection Also, this layer is the one that provides support for text and font handling —  such as layout and rendering For more information on the Media layer, check the link labeled Media Layer at www .dummies. com/go/iosprogramminglinks Cocoa Touch layer The Cocoa Touch layer contains most of the object-oriented developer-facing frameworks for building iOS applications It’s your single point of entry to app... this book, I cover such access in the appropriate chapters in the book For a complete list of the iOS frameworks, check the link labeled iOS Frameworks at www .dummies. com/go/iosprogramminglinks Xcode Xcode is two things It’s the kernel (the engine according to Apple) of Apple’s integrated development environment (IDE) for OS X and iOS It’s also the name of the IDE application itself With Xcode, you can . to www .dummies. com/cheatsheet/beginningiosprogramming www.it-ebooks.info by Rajiv Ramnath and Cheyney Long Beginning iOS Programming www.it-ebooks.info Beginning iOS Programming For Dummies ® Published. download. • iOS iseverywhere—getstartedwithcreatingapps for thishighly popularmobileoperatingsystem •Meetingthemethodsandplatforms—takeyourobject-oriented programming tothenextlevelwiththeXcodeDevelopment Environment •Makingyour iOS appsgreat—makeuser-friendlyappsthatare fast,responsive,complete,robust,reliable,andsecure •Connectingyourapps—publishyourappsintheAppStore andbecomean iOS programming star •Studyup—usealonglistofresourcestofindoutmoreabout object-orientedand iOS programming Beginning iOS Programming Ramnath Rajiv Ramnath, PhD Author of Android 3 SDK Programming For Dummies Learnto: •Program in the iOS environment using Xcode ®. articles covering additional topics at www .dummies. com/extras/beginningiosprogramming ✓ The Cheat Sheet for this book is at www .dummies. com/cheatsheet/beginningiosprogramming ✓ Updates to this book,

Ngày đăng: 01/08/2014, 17:33

Mục lục

  • Contents at a Glance

  • Table of Contents

  • Introduction

    • About This Book

    • Foolish Assumptions

    • Icons Used in This Book

    • Beyond the Book

    • Part I: Getting Started with iOS Programming

      • Chapter 1: Entering Mobile Application Development

        • Apps for a Mobile Platform

        • iOS Benefits

        • iOS App Development Essentials

        • The Application Model

        • Object-Orientation Concepts

        • Chapter 2: Object-Oriented Design Principles

          • Basic Object-Oriented Concepts

          • Principles of Object-Orientation

          • Designing an Object-Oriented Application

          • Advanced OO Techniques

          • The Application Development Lifecycle

          • Chapter 3: Effectively Using Objective-C

            • Examining an Objective-C Program

            • Defining Classes

            • Using Classes, Objects, Methods, and Variables

            • Managing Memory

Tài liệu cùng người dùng

Tài liệu liên quan