ebook img

iOS Apps for Masterminds: How to take advantage of Swift to create insanely great apps for iPhones and iPads PDF

1289 Pages·2016·10.48 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 Apps for Masterminds: How to take advantage of Swift to create insanely great apps for iPhones and iPads

iOS Apps for Masterminds How to take advantage of Swift to create insanely great apps for iPhones and iPads J.D Gauchat www.jdgauchat.com Edited by: Gina Fusco www.reword.ca Cover Illustration by Patrice Garden www.smartcreativz.com iOS Apps for Masterminds Copyright © 2016 by John D Gauchat All Rights Reserved No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system without the prior written permission of the copyright owner. Companies, services, or product names used in this book are for identification purposes only. All trademarks and registered trademarks are the property of their respective owners. Apple™, iPhone™, iPad™ and iPod Touch™ are trademarks of Apple Inc. For information on translations, please visit www.formasterminds.com The information in this book is distributed on an "as is" basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author nor Mink Books shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. The source code for this book is available at www.formasterminds.com Registration Number: 1126232 1st Edition 2016 John D Gauchat Table of Contents INTRODUCTION CHAPTER 1 1.1 Overview Requirements. Mobile Operative Systems 1.2 Xcode Running Xcode 1.3 Development Programming Languages, Cocoa Touch API, Compiler CHAPTER 2 2.1 Computer Programs Playground 2.2 Variables Memory, Primitive Types, Declaration and Initialization, Arithmetic Operators, Constants 2.3 Data Types Characters, Strings, Booleans, Optionals, Tuples 2.4 Collections Arrays, Sets, Dictionaries 2.5 Conditionals and Loops If and Else, Switch, While and Repeat While, For, For In, Control Transfer Statements 2.6 Enumerations Associated Values CHAPTER 3 3.1 Programming Paradigms 3.2 Functions Declaration of Functions, Standard Functions, Scopes, Closures 3.3 Structures Definition of Structures, Methods, Initialization, Property Keywords, Computed Properties, Type Properties and Methods, Primitive Type Structures and Casting, String Structures, Array Structures, Set Structures, Dictionary Structures 3.4 Enumerations 3.5 Objects Definition of Objects, Property Observers, Type Properties and Methods, Optional Chaining, Reference Types, Memory Management, Inheritance, Type Casting, AnyObject, Initialization, Deinitialization 3.6 Protocols Definition of Protocols, Extensions, Delegates CHAPTER 4 4.1 iOS SDK Importing Frameworks 4.2 Foundation More Standard Functions, Strings, Ranges, Numbers, Dates 4.3 Core Graphics CGGeometry 4.4 UIKit UIApplication, UIDevice, UIScreen, UIWindow, UIView, UIView Subclasses, UILabel, UIProgressView, UIActivityIndicatorView, UIControl, UIButton, UISegmentedControl, UISwitch, UISlider, UIStepper CHAPTER 5 5.1 The Interface Xcode Projects, Xcode Tools, Running the Project 5.2 Templates MVC, Application Delegate, Storyboard, View Controllers 5.3 Interface Builder Object Library, Guidelines, Properties 5.4 Connections Outlets, Connections in the Storyboard, Actions, Outlet Collections, Real-Life Application CHAPTER 6 6.1 Adaptivity 6.2 Auto Layout Constraints, Assigning Constraints, Editing Constraints, Standard Values, Resolving Auto Layout Issues, Intrinsic Content Size, Multiple Views Constraints, Relations and Priorities, Constraints in the Document Outline Panel, NSLayoutConstraint, Real-Life Application 6.3 Size Classes Grid, Adapting Constraints, Adapting Elements, Adapting Fonts, UITraitCollection, Orientation, Previews CHAPTER 7 7.1 Input and Output UITextField, UITextView, Keyboard CHAPTER 8 8.1 Images UIImage and UIImageView, Visual Effects, Assets Catalog, Icons, Launching Image CHAPTER 9 9.1 Listing Values UIPickerView, UIDatePicker CHAPTER 10 10.1 NSTimer CHAPTER 11 11.1 Scroll Views Scrolling, Zooming, Pages, Scrolling the Interface CHAPTER 12 12.1 Gesture Recognizers CHAPTER 13 13.1 Multiple View Controllers Segues, Unwind Segues, Segues in Code 13.2 Navigation Controllers Navigation Controllers in the Storyboard, Navigation Bar, Items, Toolbar, Custom Navigation, Orientation, Sharing Data 13.3 Tab Bar Controllers Tabs, UITabBarController, Delegate, Real-Life Application CHAPTER 14 14.1 Tables UITableView, UITableViewCell, Table View Protocols, NSIndexPath, Implementing Table Views, Selection, Sections and Indexes, Custom Cells, Self- Sizing Cells 14.2 Table Views and Navigation Controllers Adding Rows, Deleting Rows, Moving Rows 14.3 UITableViewController Static Tables 14.4 Search UISearchBar CHAPTER 15 15.1 A Collection of Views UICollectionView, UICollectionViewCell, UICollectionViewFlowLayout, Collection View Protocols, Layout Protocol, Implementing Collection Views, Scroll Direction, Selection Supplementary Views, Flow Layout, Custom Layout, Real-Life Application CHAPTER 16 16.1 Universal Container UISplitViewController, UISplitViewControllerDelegate, Implementing Split View Controllers 16.2 Improving the Interface Item by Default, Detail View by Default, Display Mode Button, Split View Controller Delegate 16.3 Expanding the Interface Modal Views, UIPresentationController, UIPopoverPresentationController CHAPTER 17 17.1 Alert Views Alerts, Action Sheets CHAPTER 18 18.1 Notification Center System Notifications 18.2 Local Notifications 18.3 Key/Value Observing KVC, KVO CHAPTER 19 19.1 Errors Throwing Errors, Handling Errors CHAPTER 20 20.1 Queues Operations, Main Queue CHAPTER 21 21.1 User Preferences NSUserDefaults 21.2 Files NSFileManager, URLs and Paths, Files and Directories, Files Attributes, Files Content, NSBundle 21.3 Archiving Encoding and Decoding, Real-Life Application CHAPTER 22 22.1 Custom Object Graph Data Model, Core Data Stack, NSManagedObject, Managing Objects, Counting Objects, Predicates, Sort Descriptors, Delete Objects 22.2 Fetched Results Controller Sections, Search 22.3 Migration CHAPTER 23 23.1 Data in the Cloud Enabling iCloud, Testing Devices 23.2 Key/Value Storage 23.3 UIDocument Multiple Documents 22.4 Core Data in iCloud Seeding the Store, Duplicates CHAPTER 24 24.1 Core Graphics Destination, Context, Paths, Colors, Configuration, Saving the State, Clipping, Gradients, Shadows, Transformations, Text, Images, Drawing Cycle, Image Context 24.2 Core Animation CALayer, 3D Transformations, CABasicAnimation, UIView Animations CHAPTER 25 25.1 Video AVAsset, AVPlayerItem, AVPlayer, AVPlayerLayer, CMTime, Video Player, AVKit 25.2 Audio AVAudioPlayerDelegate, Recording 25.3 Media Media Controller, Query Media CHAPTER 26 26.1 Image Picker Controller Camera, Photos Library, Adapting the Controller, Storing Pictures, Modifying Pictures 26.2 Custom Controllers Camera, Photos, Videos 26.3 Core Image CHAPTER 27 27.1 Links 27.2 Web Views App Transport Security 27.3 Web Content JSON, XML 27.4 Social Networks UIActivityViewController, SLComposeViewController, SLRequest CHAPTER 28 28.1 Contacts Reading Contacts, Formatters, Working with Contacts, CNContactViewController, CNContactPickerViewController CHAPTER 29 29.1 Core Motion Motion Device, Motion Activity, Pedometer, Altimeter 29.2 Core Location Authorization, Getting the Location, Background Location, Region, Geocoding CHAPTER 30 30.1 Map View Configuring the Map, Annotations, User Location, Search, Directions CHAPTER 31 31.1 Internationalization Formatters, Languages, Translation, NSLocalizedString, Resources CHAPTER 32 32.1 Publishing Apple Developer Program, Certificates, Provisioning Profiles, and Identifiers, iTunes Connect, Submitting the Application Introduction The first iPhone was regarded as a revolutionary piece of technology, but not for the right reasons. At that moment, the innovation presented by this gadget was clearly changing our understanding of telecommunications and the preconceptions we had of what a phone could do, but nobody, not even Apple, was able to predict the impact that such an amazing piece of engineering would have in the software industry. At first, Apple's plan was to follow the trend. They wanted to provide a new communication device with enhanced capabilities but under their strict control. The device would be capable of running its own applications, also called apps or native apps, but only those created by the company would be available. Each user would have the same apps as everybody else and only access third-party applications from the web and through the browser that was delivered with the system. Apple was trying to focus its strategy on web applications and emerging web technologies, like everybody else, but the incredible possibilities offered by the iPhone inevitably altered its plans. The innovations introduced by this powerful device caught developers' attention all around the world, and the interest to create native applications grew fast. Soon, methods to install unauthorized applications were created and popularized. Dozens of third-party applications were developed and shared through open markets online. The success of these first apps and the willingness of users to install them (under the risk of damaging their devices) made clear that not many people agreed with the company’s initial intentions. It was evident that users preferred to tap on an icon and work with the app right away rather than open a browser, remember a domain, type it, and wait for the web application to load. These applications were easy to access, focused on a single purpose, and visually more appealing than a website. Developers wanted to create and users wanted to consume native apps. This external pressure, along with internal demands from executives in Apple’s headquarters, motivated a change in Steve Jobs’s mind, and the creation of the App Store was announced. The creation of the App Store not only meant that an official place to sell apps was going to be available, but also that a whole set of tools was going to be provided by the company itself to create them. The App Store and the iOS SDK (Software Development Kit) changed everything for good. Developers now had the right tools to build their apps and users had a safe place to buy them. Soon, thousands of native apps were available, generating an excellent alternative to web applications and creating a whole new market. The new apps attracted more customers for Apple’s devices, which motivated the creation of more apps, in a positive spiral that generated billions of dollars. Several applications created by developers working alone from their bedrooms became an overnight success, triggering a gold rush, the effects of which are still visible nowadays. The new distribution channels and the production tools provided by Apple have initiated a golden era for developers. The possibility and opportunities are infinite. Native applications are here to stay, the market they have created is growing by the day, and now you can be part of it. IMPORTANT: Supporting links, examples, projects, videos, and resources are available on our website: www.formasterminds.com. Apple's official documentation is available at developer.apple.com. Chapter 1 App Development 1.1 Overview The decision to create the App Store and open the platform to developers was not an easy one. Steve Jobs didn’t like the idea of exposing his highly praised new creation to the same threats of personal computers. He didn’t want the bad reputation his devices could get once affected by viruses or attacked by hackers. He insisted on keeping the platform closed until he realized that they could take advantage of the systems already developed by Apple for the iTunes Store to stay in control of quality and sales. This decision didn’t come without a price for developers. The system is open enough to allow full creativity, but it’s still under Apple’s strict supervision, which means developers can only work according to the company’s rules. Requirements Apple requires developers to use the software provided by the company to create apps for its mobile devices. This software only works in Apple’s computers and requires the developer to have an Apple account. For these reasons, the options are very limited, but the good news is that most of the things we need are provided for free. Mac Computer—This in theory could be any Intel-based Mac computer, but the development software always requires the latest operative system (OS X), so in practice we need a relatively new computer. Apple Developer Account—This is a basic account we can get for free; it gives us access to the Member Center where we can watch videos, download programming guides, read the official documentation, get sample codes, and more. Xcode—This is the software provided by Apple for development. The current version is number 7. It’s free and the package comes with everything we need to create our apps, including an editor, the SDK (Software Development Kit), and a simulator to test the applications. Apple Developer Program—This service is required to publish our apps in the App Store and implement services like iCloud, so we will need to enrol in this program as soon as our first app is ready for distribution. At this moment the membership costs $99 US dollars per year. Mobile Device—This could be any of the devices available in the market, including iPads, iPhones, and iPods, but at the time of picking one for testing we have to consider that old models don’t support the current versions of Apple’s mobile operative system (iOS). Testing our applications in a real device is highly recommended and necessary before publishing. The setup is relatively simple. We have to get a Mac Computer capable of running the operative system currently required by Xcode (at the time of this writing, it is OS X 10.9), open an Apple developer account from developer.apple.com using our personal Apple ID (the one that is created when we initialized our computer), and install the latest version of Xcode (currently 7). Xcode has everything we need, including a simulator to test mobile applications on the computer. Once the applications are created, we have to enrol to the Apple Developer Program to generate all the certificates and permissions we need to submit our apps to the App Store and put them up for sale. Mobile Operative Systems iOS is the name of the operative system delivered by Apple with every mobile device sold. The system is currently in version number 9. Applications programed in the Swift language only work on systems from version 7, but this doesn’t reduce or affect the potential market for these applications because most devices are capable of updating their system to the latest one. At the time of this writing, it is estimated that more than 90% of Apple devices in the market are running iOS 8 or 9. 1.2 Xcode Xcode is a general-purpose IDE (Integrated Development Environment). It includes a very powerful editor with graphic tools to help us write our code, and comes with the SDKs (Software Development Kits) for the creation of software for the iOS and OS X operative systems. The SDKs include compilers for Objective-C and the new Swift language. From Xcode, we can program software for every Apple’s platform using any of these programming languages. Xcode is available as an app on the Mac App Store. To download this application, we have to open the App Store from Launchpad (the application organizer that comes with OS X) or double click the App Store icon inside the Applications folder in Finder (OS X’s file explorer). From the App Store, we have to search for the term "Xcode". The window will show the Xcode’s icon at the top (Figure 1-1, number 1). We have to click on the Free button to download the software. Figure 1-1: Xcode in the Mac App Store Running Xcode Once the downloading process is over, the software is automatically installed. To open Xcode we have to go to Launchpad and click on the icon or search for the program inside the Applications folder in Finder. Figure 1-2 shows Xcode's welcome screen.

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.