ebook img

iOS 10 Programming Fundamentals with Swift: Swift, Xcode, and Cocoa Basics PDF

620 Pages·2016·7.3 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview iOS 10 Programming Fundamentals with Swift: Swift, Xcode, and Cocoa Basics

X c C o o d v e er 8 s , i a O n S d 1 Sw0, i f t 3 iOS 10 Programming Fundamentals with Swift SWIFT, XCODE, AND COCOA BASICS Matt Neuburg THIRD EDITION iOS 10 Programming Fundamentals with Swift Swift, Xcode, and Cocoa Basics Matt Neuburg Boston iOS 10 Programming Fundamentals with Swift, Third Edition by Matt Neuburg Copyright © 2017 Matt Neuburg. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://safaribooksonline.com). For more information, contact our corporate/ institutional sales department: 800-998-9938 or [email protected]. Editor: Rachel Roumeliotis Cover Designer: Karen Montgomery Production Editor: Kristen Brown Interior Designer: David Futato Proofreader: O’Reilly Production Services Illustrator: Matt Neuburg Indexer: Matt Neuburg April 2015: First Edition October 2015: Second Edition October 2016: Third Edition Revision History for the Third Edition 2016-09-23: First release See http://oreilly.com/catalog/errata.csp?isbn=9781491970072 for release details. The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. iOS 10 Programming Fundamentals with Swift, the image of a harp seal, and related trade dress are trademarks of O’Reilly Media, Inc. While the publisher and the author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights. ISBN: 978-1-491-97007-2 [LSI] Table of Contents Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi Part I. Language 1. The Architecture of Swift. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Ground of Being 3 Everything Is an Object? 5 Three Flavors of Object Type 6 Variables 6 Functions 8 The Structure of a Swift File 9 Scope and Lifetime 11 Object Members 12 Namespaces 13 Modules 14 Instances 15 Why Instances? 17 self 19 Privacy 20 Design 22 Object Types and APIs 23 Instance Creation, Scope, and Lifetime 25 Summary and Conclusion 26 2. Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 Function Parameters and Return Value 27 Void Return Type and Parameters 31 Function Signature 32 iii External Parameter Names 32 Overloading 34 Default Parameter Values 35 Variadic Parameters 36 Ignored Parameters 36 Modifiable Parameters 37 Function In Function 41 Recursion 43 Function As Value 43 Anonymous Functions 46 Define-and-Call 52 Closures 53 How Closures Improve Code 54 Function Returning Function 56 Closure Setting a Captured Variable 58 Closure Preserving Its Captured Environment 59 Escaping Closures 60 Curried Functions 61 Function References and Selectors 62 Function Reference Scope 65 Selectors 66 3. Variables and Simple Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 Variable Scope and Lifetime 69 Variable Declaration 71 Computed Initializer 74 Computed Variables 75 Setter Observers 78 Lazy Initialization 80 Built-In Simple Types 82 Bool 82 Numbers 84 String 90 Character 95 Range 98 Tuple 100 Optional 103 4. Object Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 Object Type Declarations and Features 117 Initializers 119 Properties 125 iv | Table of Contents Methods 128 Subscripts 130 Nested Object Types 132 Instance References 133 Enums 135 Raw Values 137 Associated Values 138 Enum Initializers 139 Enum Properties 140 Enum Methods 141 Why Enums? 142 Structs 143 Struct Initializers, Properties, and Methods 144 Struct As Namespace 145 Classes 146 Value Types and Reference Types 146 Subclass and Superclass 151 Class Initializers 156 Class Deinitializer 164 Class Properties and Methods 164 Polymorphism 166 Casting 169 Type Reference 174 Protocols 179 Why Protocols? 181 Protocol Type Testing and Casting 183 Declaring a Protocol 183 Optional Protocol Members 185 Class Protocol 186 Implicitly Required Initializers 187 Literal Convertibles 189 Generics 190 Generic Declarations 192 Type Constraints 194 Explicit Specialization 196 Associated Type Chains 197 Additional Constraints 200 Extensions 203 Extending Object Types 203 Extending Protocols 206 Extending Generics 209 Umbrella Types 210 Table of Contents | v Any 211 AnyObject 212 AnyClass 215 Collection Types 216 Array 216 Dictionary 230 Set 235 5. Flow Control and More. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241 Flow Control 241 Branching 242 Loops 254 Jumping 259 Operators 274 Privacy 277 Private and Fileprivate 278 Public and Open 280 Privacy Rules 280 Introspection 281 Memory Management 282 Weak References 284 Unowned References 285 Weak and Unowned References in Anonymous Functions 287 Memory Management of Protocol-Typed References 290 Part II. IDE 6. Anatomy of an Xcode Project. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293 New Project 294 The Project Window 296 The Navigator Pane 297 The Utilities Pane 303 The Editor 304 The Project File and Its Dependents 306 The Target 309 Build Phases 310 Build Settings 312 Configurations 313 Schemes and Destinations 314 From Project to Running App 316 Build Settings 319 vi | Table of Contents Property List Settings 319 Nib Files 320 Additional Resources 321 Code Files and the App Launch Process 324 Frameworks and SDKs 329 Renaming Parts of a Project 331 7. Nib Management. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333 The Nib Editor Interface 335 Document Outline 336 Canvas 339 Inspectors and Libraries 341 Nib Loading 342 When Nibs Are Loaded 343 Manual Nib Loading 344 Connections 346 Outlets 346 The Nib Owner 348 Automatically Configured Nibs 351 Misconfigured Outlets 352 Deleting an Outlet 353 More Ways to Create Outlets 354 Outlet Collections 357 Action Connections 357 More Ways to Create Actions 360 Misconfigured Actions 361 Connections Between Nibs — Not! 361 Additional Configuration of Nib-Based Instances 362 8. Documentation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367 The Documentation Window 367 Class Documentation Pages 369 Quick Help 372 Symbols 374 Header Files 375 Sample Code 376 Internet Resources 376 9. Life Cycle of a Project. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379 Device Architecture and Conditional Code 379 Backward Compatibility 380 Device Type 381 Table of Contents | vii Version Control 383 Editing and Navigating Your Code 385 Autocompletion 386 Snippets 388 Fix-it and Live Syntax Checking 389 Navigation 390 Finding 391 Running in the Simulator 393 Debugging 394 Caveman Debugging 394 The Xcode Debugger 396 Testing 403 Clean 409 Running on a Device 410 Obtaining a Developer Program Membership 410 Signing an App 411 Automatic Development Signing 412 Obtaining a Development Certificate Manually 415 Obtaining a Development Provisioning Profile Manually 416 Running the App 418 Managing Certificates, Profiles, and Devices 418 Profiling 419 Gauges 420 Memory Debugging 421 Instruments 422 Localization 425 Localizing the Info.plist 426 Localizing a Nib File 427 Localizing Code Strings 429 Localizing With XML Files 431 Distribution 433 Making an Archive 433 Obtaining a Distribution Certificate Manually 434 Obtaining a Distribution Profile Manually 435 Ad Hoc Distribution 436 Final App Preparations 437 Icons in the App 437 Other Icons 439 Launch Images 439 Screenshots and Video Previews 440 Property List Settings 442 viii | Table of Contents

Description:
Move into iOS development by getting a firm grasp of its fundamentals, including the Xcode IDE, the Cocoa Touch framework, and Swift 3—the latest version of Apple’s acclaimed programming language. With this thoroughly updated guide, you’ll learn Swift’s object-oriented concepts, understand h
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.