Xcode 7 Essentials - Second Edition
By Ohland Brett and Jayant Varma
()
About this ebook
Step up your iOS development with the power and wealth of features of Xcode 7
About This Book- Updated for the latest Xcode 7 release, this is the first book that will show you how to use all the new features available in Xcode 7 to their fullest
- This guide to will get you up and running with the entire workflow to develop Apple apps without previous Xcode experience
- Packed with plenty of tips on how to use Xcode with Swift 2 and other existing Apple frameworks to develop robust apps at a rapid pace
If you are a novice programmer who is familiar with the concepts of object-oriented programming, but have little to no knowledge of Swift, Xcode, or Apple's Cocoa APIs, then this book is for you. Starting with an introduction to the basics of Xcode and the Swift programming language, you will learn all of the skills that are essential to build an app and submit it to the App Store
What You Will Learn- Get an introduction to Xcode and get to know how to navigate and use the tool
- Build playgrounds to learn and explore the environment
- Create an adaptive UI with the interface builder that will help your app to scale through a wide range of devices
- Understand Table, Collection, and Stack views and find out how they can be implemented
- Create custom components for your application through frameworks and live previews
- Exploit Xcode's advanced features to elevate your debugging and testing capabilities
- Run your application on the physical device and submit it to the App store
Apple's Xcode technology is making the development curve smoother than it has ever been with its easy-to-develop features and enhancements. With the latest release of Xcode 7, Apple has also added great support for Swift development.
This book will introduce you to all the new features of Xcode 7 and demonstrate how Swift programming can be much easier, faster, and simply better with Xcode!
Even if you're starting with just a little knowledge of Swift or Xcode, you will learn the basics of the language as well as the tool. You will then use this knowledge to create simple applications and will learn how to debug and optimize your code. At the end of this book, you would have learned enough to build, run and submit your very own application to the App Store.
Style and approachThis is a step-by-step guide, full of practical and real world examples, to help you get to grips with Xcode with ease. A demo project is also provided at the end of the book, where you can test your skills.
Related to Xcode 7 Essentials - Second Edition
Related ebooks
Application Development in iOS 7 Rating: 0 out of 5 stars0 ratingsSwift 2 Blueprints: Swift Blueprints Rating: 0 out of 5 stars0 ratingsiOS 13 Programming for Beginners: Get started with building iOS apps with Swift 5 and Xcode 11 Rating: 0 out of 5 stars0 ratingsRubyMotion iOS Develoment Essentials Rating: 0 out of 5 stars0 ratingsiOS 9 Game Development Essentials Rating: 0 out of 5 stars0 ratingsLearn Swift by Building Applications: Explore Swift programming through iOS app development Rating: 0 out of 5 stars0 ratingsInstant PhoneGap Social App Development Rating: 0 out of 5 stars0 ratingsTest-Driven iOS Development with Swift 3 Rating: 0 out of 5 stars0 ratingsOpa Application Development Rating: 0 out of 5 stars0 ratingsProtocol-Oriented Programming with Swift Rating: 0 out of 5 stars0 ratingsiOS 5 Essentials Rating: 0 out of 5 stars0 ratingsTest-Driven iOS Development with Swift 4 - Third Edition: Write Swift code that is maintainable, flexible, and easily extensible Rating: 0 out of 5 stars0 ratingsInstant Android Fragmentation Management How-to Rating: 0 out of 5 stars0 ratingsiOS 15 Programming for Beginners: Kickstart your mobile app development journey by building iOS apps with Swift 5.5 and Xcode 13 Rating: 0 out of 5 stars0 ratingsLearning Ionic, Second Edition: Hybrid mobile apps with HTML5, CSS3, and Angular Rating: 0 out of 5 stars0 ratingsMastering Android Wear Application Development Rating: 0 out of 5 stars0 ratingsLearning Swift - Second Edition Rating: 0 out of 5 stars0 ratingsSwift 2 Design Patterns Rating: 0 out of 5 stars0 ratingsLearning Behavior-driven Development with JavaScript Rating: 5 out of 5 stars5/5Cocos2D Game Development Essentials Rating: 0 out of 5 stars0 ratingsAndroid System Programming Rating: 5 out of 5 stars5/5PhoneGap and AngularJS for Cross-platform Development Rating: 0 out of 5 stars0 ratingsReactive Programming with Swift Rating: 0 out of 5 stars0 ratingsInstant Play Framework Starter: Build your web applications from the ground up with the Play Framework for Java and Scala Rating: 0 out of 5 stars0 ratingsAppium Essentials Rating: 0 out of 5 stars0 ratingsApplication Development with Swift Rating: 0 out of 5 stars0 ratingsPhoneGap for Enterprise Rating: 0 out of 5 stars0 ratingsMastering PhoneGap Mobile Application Development Rating: 0 out of 5 stars0 ratingsAndroid Application Programming with OpenCV Rating: 3 out of 5 stars3/5Mastering Play Framework for Scala Rating: 0 out of 5 stars0 ratings
Computers For You
Storytelling with Data: Let's Practice! Rating: 4 out of 5 stars4/5Elon Musk Rating: 4 out of 5 stars4/5Algorithms to Live By: The Computer Science of Human Decisions Rating: 4 out of 5 stars4/5Creating Online Courses with ChatGPT | A Step-by-Step Guide with Prompt Templates Rating: 4 out of 5 stars4/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5Mastering ChatGPT: 21 Prompts Templates for Effortless Writing Rating: 4 out of 5 stars4/5Everybody Lies: Big Data, New Data, and What the Internet Can Tell Us About Who We Really Are Rating: 4 out of 5 stars4/5Data Analytics for Beginners: Introduction to Data Analytics Rating: 4 out of 5 stars4/5The Innovators: How a Group of Hackers, Geniuses, and Geeks Created the Digital Revolution Rating: 4 out of 5 stars4/5Get Into UX: A foolproof guide to getting your first user experience job Rating: 4 out of 5 stars4/5Learning the Chess Openings Rating: 5 out of 5 stars5/5Master Obsidian Quickly: Boost Your Learning & Productivity with a Free, Modern, Powerful Knowledge Toolkit Rating: 4 out of 5 stars4/5Product Operations: How successful companies build better products at scale Rating: 0 out of 5 stars0 ratingsThe Alignment Problem: How Can Machines Learn Human Values? Rating: 4 out of 5 stars4/5Artificial Intelligence: The Complete Beginner’s Guide to the Future of A.I. Rating: 4 out of 5 stars4/5Blender 3D By Example Rating: 4 out of 5 stars4/5UX/UI Design Playbook Rating: 4 out of 5 stars4/5Blender 3D Basics Beginner's Guide Second Edition Rating: 5 out of 5 stars5/5Becoming a Data Head: How to Think, Speak, and Understand Data Science, Statistics, and Machine Learning Rating: 5 out of 5 stars5/5People Skills for Analytical Thinkers Rating: 5 out of 5 stars5/5Data Visualization with Excel Dashboards and Reports Rating: 4 out of 5 stars4/5Thinking in Algorithms: Strategic Thinking Skills, #2 Rating: 4 out of 5 stars4/5
Reviews for Xcode 7 Essentials - Second Edition
0 ratings0 reviews
Book preview
Xcode 7 Essentials - Second Edition - Ohland Brett
Table of Contents
Xcode 7 Essentials Second Edition
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Introduction to Xcode
Requirements and getting Xcode
Features of Xcode
What's new in Xcode 7?
Sideloading
Swift 2
Playgrounds
Testing
Crash logs
Summary
2. A tour of Xcode
Starting Xcode
Creating a new project
Choosing a template
Choosing the project options
Setting the project properties
Xcode overview
The toolbar area
The navigator area
The editor area
The Standard editor
The Assistant editor
The comparison editor
The utilities area
The debug area
Development languages
Summary
3. Playgrounds
Before we start
The storyboard workspace
Learning Swift
Working with constants and variables
Value types
Working with strings
Working with numbers
Working with Booleans
Adding different types
Collection types
Array type
Creating arrays
Accessing items
Modifying arrays
Loops and iteration
Dictionary type
Creating dictionaries
Accessing items
Modifying items
Loops and iteration
Set type
Creating sets
Accessing, modifying, and iterating through a set
Set operations
The Any and AnyObject types
Optionals
Unwrapping optionals
if let
guard let
Unwrapping multiple optionals
Optional chaining
Tuples
Accessing items
Conditional statements
The if statement
The switch statement
The guard statement
Loops
For and for in
While and repeat-while
Breaking or continuing
Functions and closures
Returns
Parameters
Closures
Classes and structures
Classes versus structures
Extending classes and structures
Enumerations
Error handling
Propagating errors
Handling errors, do-catch and try?
do catch
Try?
Asserting errors
Defer statements
Summary
4. Interface Builder
Model View Controller
Understanding Interface Builder
Views and View Controllers
Adding elements to your view
Adaptive UI
Size Classes
Auto Layout
Debugging Auto Layout
Tweaking values
Pinning
Relative positioning
Adding more views
Navigation controllers
Connecting views and controllers
Subclassing UIViewController
Understanding subclassing
Creating connections, outlets and actions
Different elements in different Size Classes
Layout previews
Managing connections
Adding gesture recognizers
Summary
5. Table, Collection, and Stack Views
Plain views versus Table, Collection, and Stack views
Static table views
Dynamic table views
Data sources
Delegates
Bringing it all together
Collection views
Starting the example
Creating a custom UICollectionViewCell
Stack views
What about OS X?
Summary
6. Custom Controls
Introducing Custom Controls
The basics
Starting an example project
Creating a framework
Creating a class
Properties
IBDesignable and IBInspectable
Advanced drawing with CALayer
Debugging Custom Controls
Summary
7. Debugging
Breakpoints
Listing breakpoints
The debug area
The variables view
The console area
The debug navigator
Quick Look
Debugging the view hierarchy
Dealing with crashes
Summary
8. Testing Your Code
Test-diven development
Testing in Xcode
The test navigator
Test classes
Test methods
A simple calculator example
Assertions
Writing our first real functional unit test
Performance tests
UI tests
Running tests and collecting results
Code coverage
Summary
9. Sideloading, Optimizing, and Submitting Your App
iOS simulators
Simulating different devices
Simulator limitations
Sideloading
Getting an Apple ID
Using an Apple ID with Xcode
Registering a device
The last steps
Optimizing your app
App thinning
Slicing
Bytecode
On-demand resources
Submitting your app to the App Store
iTunes Connect
Uploading a build
Submitting your app for review
App review
App rejection
Approval — ready for sale
Summary
A. Everything Else
TestFlight
Beta App review?
Submitting your app
Installing TestFlight builds
Submitting for final sale
Crash logs
Storyboard references
Creating a new Storyboard
Refactoring existing views
Summary
Index
Xcode 7 Essentials Second Edition
Xcode 7 Essentials Second Edition
Copyright © 2016 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: January 2015
Second edition: February 2016
Production reference: 1020216
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78588-901-1
www.packtpub.com
Credits
Authors
Brett Ohland
Jayant Varma
Reviewer
Jeffrey Huang
Commissioning Editor
Wilson D'souza
Acquisition Editor
Sonali Vernekar
Content Development Editor
Kirti Patil
Technical Editor
Naveenkumar Jain
Copy Editor
Vikrant Phadke
Project Coordinator
Nidhi Joshi
Proofreader
Safis Editing
Indexer
Hemangini Bari
Production Coordinator
Shantanu N. Zagade
Cover Work
Shantanu N. Zagade
About the Authors
Brett Ohland develops software, likes to tinker and fix things (especially bikes), and keeps himself and others caffeinated. He has well over a decade of experience of converting keystrokes and staring at the ceiling into functional applications for clients.
He started his career by building Flash websites when those were still an amazing thing, transitioned to web development when everyone was loving JavaScript, and then moved on to iOS development so that he could build his dream photography app. Throughout this period, Brett has worked for major advertising agencies, consultancies of all sizes, a stock photo agency, two guys in a basement, and himself for a while. Several teaching opportunities have allowed him to share his knowledge at start-up incubators and even a university.
Currently, he writes about his technological discoveries and interests at ampersandsoftworks.com when he isn't riding his bike, chasing his toddler around the house, or pulling a shot of espresso.
Jayant Varma is a technophile with a career spanning more than two decades and was introduced to computing in the days of 8-bit computers and Z80 chips. While managing the IT and telecom department at BMW's dealerships in India and Oman, and Nissan in Qatar, he worked extensively on Windows, AS/400, and Unix. His love for traveling inspired him to work and travel to several countries. He is currently based in Australia.
Jayant's technological journey began as a Microsoft technologies developer and then diversified. His focus is now on Apple and mobile technologies. He has a master's degree in business administration and IT from James Cook University, Australia. He also lectured at James Cook University and coordinated the onshore and off-shore teaching of Linux/Unix administration. Jayant has worked closely with the Australian Computer Society (ACS) and Apple University Consortium (AUC) on workshops and projects.
He authored the book Learn Lua for iOS Game Development, Apress, and has also been a technical reviewer on several titles. As a founder, consultant, and developer at OZApps (www.oz-apps.com), he helps organizations and individuals integrate technology into their businesses and strategies. He also conducts training sessions and workshops, and writes blogs to share his knowledge with the community.
About the Reviewer
Jeffrey Huang is an iOS developer and App maker. He has one published app on the iOS app store. He also has a YouTube channel that teaches iOS and electronics (https://www.youtube.com/user/JeffreyApp). Recently, Jeffrey also spearheaded a new initiative, Chicago Technology for Kids, to promote fun technology learning among kids.
www.PacktPub.com
Support files, eBooks, discount offers, and more
For support files and downloads related to your book, please visit www.PacktPub.com.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
Support files, eBooks, discount offers, and morehttps://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.
Why subscribe?
Fully searchable across every book published by Packt
Copy and paste, print, and bookmark content
On demand and accessible via a web browser
Free access for Packt account holders
If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.
Preface
Welcome to Xcode 7 Essentials. Developing apps for desktop and mobile computers has never been easier for anyone to do. The technical and commuting requirements are such that practically anyone can make and release an app to millions of users. With well over a billion iOS devices and nearly half a billion Macs in people's homes and businesses, there is a real market for any piece of software, no matter how specialized. Apple has fostered this market by continually updating Xcode, their free development tool, to keep it modern, easy to use, and powerful.
This book will be covering Xcode 7, the current version of the app, as well as the Swift programming language. The book starts with a basic tour of Xcode, takes you through many of the features of making the app, and ends with how to submit your app to the app store of your choice using a combination of theory and step-by-step guides.
What this book covers
Chapter 1, Introduction to Xcode, introduces Xcode and shows you how to find, install, and set it up for use.
Chapter 2, Tour of Xcode, takes a deeper look at the tool itself. Here, you become familiar with the interface and its features.
Chapter 3, Playgrounds, introduces Playgrounds, an interactive environment for learning and experimenting with the Swift programming language. This chapter will then walk you through many of Swift's features and its syntax to help you express yourself in code.
Chapter 4, Interface Builder, covers Interface Builder and Storyboards, Xcode's tools for creating user interfaces by dragging and dropping elements on a screen.
Chapter 5, Table, Collection, and Stack Views, uses the knowledge gained in the previous chapters and shows you how three advanced view types will let you build complicated-looking layouts quickly and easily.
Chapter 6, Custom Controls, shows you how you can create custom, live-updating controls for your applications, and how to easily share them across projects as a framework.
Chapter 7, Debugging, shows you the tools that Xcode provides to help you become a great detective and exterminator of bugs and crashes in your code.
Chapter 8, Testing Your Code, introduces the concepts behind test-driven development and the unit test and UI testing tools that Xcode provides to help you write great code.
Chapter 9, Sideloading, Optimizing, and Submitting Your App, shows you how to run your app on a physical device, how it can be optimized, and the steps necessary to submit it to the app store of your choice.
Appendix, Everything Else, covers more advanced topics. These include distributing beta versions of your app using TestFlight, collecting and reading crash reports submitted to you by those testers, and how to simplify your user interfaces with Soryboard references.
What you need for this book
To be able to run the code and work through the chapters step by step, you will need the following:
An Apple computer running OS X 10.10.5 or higher
Xcode 7.x installed on this Apple computer
Who this book is for
This book is aimed at a novice programmer who is familiar with the concepts of object-oriented programming, but has little to no knowledge of Swift, Xcode, or Apple's Cocoa APIs. Starting with an introduction to the basics of Xcode and the Swift programming language, they will learn all the skills that are essential for building an app and submitting it to the app store.
Conventions
In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: UILabel can be used to show text on the screen.
A block of code is set as follows:
let name: String = XCodeEsentials
let version: Int = 1.0
let title = \(name) - ver (\version)
print(The book is \(title)
)
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
var width: Int = 200
var height: Int = 200
@IBInspectabletheColor: UIColor = UIColor.redColor()
var title: String = Untitled
Any command-line input or output is written as follows:
po UIScreen().bounds
New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: Reinstalling the app is as simple as pressing the GET button again anytime in the future.
Note
Warnings or important notes appear in a box like this.
Tip
Tips and tricks appear like this.
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.
To send us general feedback, simply e-mail <[email protected]>, and mention the book's title in the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.
Customer support
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
Downloading the example code
You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to