Application Development with Swift
()
About this ebook
Develop highly efficient and appealing iOS applications by using the Swift language
About This Book- Develop a series of applications with Swift using the development kits and new/updated APIs
- Use the new features of iOS 8 to add new flavor to your applications
- A hands-on guide with detailed code snippets to aid you in developing powerful Swift applications
If you are an iOS developer with experience in Objective-C, and wish to develop applications with Swift, then this book is ideal for you. Familiarity with the fundamentals of Swift is an added advantage but not a necessity.
What You Will Learn- Use playgrounds in Xcode to make the writing of Swift code productive and easy
- Get acquainted with the advanced features of Swift and make complete use of them in your code
- Add a new method for authentication to your app using Touch ID
- Develop health-related apps using HealthKit
- Take your apps to the next level of performance and capability using Metal
- Develop applications for wearables using WatchKit
- Use Notification Center to easily access all your notifications
- Make your users devices more stylish by using Apple's built-in Quick Type keyboard, instead of the native one
After years of using Objective-C for developing apps for iOS/Mac OS, Apple now offers a new, creative, easy, and innovative programming language for application development, called Swift. Swift makes iOS application development a breeze by offering speed, security and power to your application development process. Swift is easy to learn and has awesome features such as being open source, debugging,interactive playgrounds, error handling model, and so on. Swift has simplified its memory management with Automatic Reference Counting (ARC) and it is compatible with Objective-C.
This book has been created to provide you with the information and skills you need to use the new programming language Swift. The book starts with an introduction to Swift and code structure. Following this, you will use playgrounds to become familiar with the language in no time. Then the book takes you through the advanced features offered by Swift and how to use them with your old Objective-C code or projects. You will then learn to use Swift in real projects by covering APIs such as HealthKit, Metal, WatchKit, and Touch ID in each chapter. The book's easy to follow structure ensures you get the best start to developing applications with Swift.
Style and approachThe book achieves its end goal by dividing its content into two parts. Part 1 will take the readers, who are new to Swift, through its architecture and basics. Part 2 of the book will cover content on application development with Swift.
Hossam Ghareeb
Hossam Ghareeb is a software engineer who graduated from the computer and system engineering department of Alexandria University in 2012. Currently, he is an iOS software engineer at Prototype Interactive in Dubai. He has a lot of experience in iOS development and software engineering; he always keeps himself up to date with new technologies. It is his passion to help people by sharing his experience and writing tutorials to get people engaged quickly without problems. His favorite hobbies are fishing and playing video games, especially FIFA and PES. If you need his help or wish to go fishing with him, then you can contact him at hossam.ghareb@gmail.com.
Related to Application Development with Swift
Related ebooks
Swift by Example Rating: 1 out of 5 stars1/5Learning Swift Rating: 5 out of 5 stars5/5Swift Programming Nuts and bolts Rating: 0 out of 5 stars0 ratingsSwift Functional Programming - Second Edition Rating: 3 out of 5 stars3/5Test-Driven iOS Development with Swift Rating: 5 out of 5 stars5/5iOS Development with SwiftUI: Acquire the Knowledge and Skills to Create iOS Applications Using SwiftUI, Xcode 13, and UIKit Rating: 0 out of 5 stars0 ratingsSwift Essentials Rating: 0 out of 5 stars0 ratingsiOS 13 Programming for Beginners - Fourth Edition: Get started with building iOS apps with Swift 5 and Xcode 11, 4th Edition Rating: 0 out of 5 stars0 ratingsSwift iOS Programming for Kids Rating: 0 out of 5 stars0 ratingsMastering Swift 5 - Fifth Edition: Deep dive into the latest edition of the Swift programming language, 5th Edition Rating: 0 out of 5 stars0 ratingsiOS 15 Application Development for Beginners: Learn Swift Programming and Build iPhone Apps with SwiftUI and Xcode 13 Rating: 0 out of 5 stars0 ratingsSwift in 30 Days: Build iOS Apps by Learning Swift, Xcode, and SwiftUI in Just Four Weeks (English Edition) Rating: 0 out of 5 stars0 ratingsSwift High Performance Rating: 4 out of 5 stars4/5JavaScript Projects for Kids Rating: 0 out of 5 stars0 ratingsSwift Essentials - Second Edition Rating: 0 out of 5 stars0 ratingsiOS Programming Nuts and bolts Rating: 4 out of 5 stars4/5TypeScript Essentials Rating: 4 out of 5 stars4/5Mastering Android Application Development Rating: 5 out of 5 stars5/5Flutter for Beginners: An introductory guide to building cross-platform mobile applications with Flutter and Dart 2 Rating: 0 out of 5 stars0 ratingsJavaScript Regular Expressions Rating: 3 out of 5 stars3/5Swift 2 Design Patterns Rating: 0 out of 5 stars0 ratingsSwift 5 for Absolute Beginners: Learn to Develop Apps for iOS Rating: 0 out of 5 stars0 ratingsLearning AngularJS Animations Rating: 4 out of 5 stars4/5Learn iOS Application Development: Take Your Mobile App Development Skills to the Next Level with Swift and Xcode (English Edition) Rating: 0 out of 5 stars0 ratingsLearning Swift - Second Edition Rating: 0 out of 5 stars0 ratingsLearning SQLite for iOS Rating: 0 out of 5 stars0 ratingsGetting Started with React Native Rating: 4 out of 5 stars4/5Learn Java 12 Programming: A step-by-step guide to learning essential concepts in Java SE 10, 11, and 12 Rating: 0 out of 5 stars0 ratingsMastering Java EE Development with WildFly Rating: 0 out of 5 stars0 ratingsClean Code in JavaScript: Develop reliable, maintainable, and robust JavaScript Rating: 5 out of 5 stars5/5
Programming For You
Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5Python: Learn Python in 24 Hours Rating: 4 out of 5 stars4/5Python: For Beginners A Crash Course Guide To Learn Python in 1 Week Rating: 4 out of 5 stars4/5SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Excel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5Python Machine Learning By Example Rating: 4 out of 5 stars4/5Python Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5A Slackers Guide to Coding with Python: Ultimate Beginners Guide to Learning Python Quick Rating: 0 out of 5 stars0 ratingsSQL: For Beginners: Your Guide To Easily Learn SQL Programming in 7 Days Rating: 5 out of 5 stars5/5Python Data Structures and Algorithms Rating: 5 out of 5 stars5/5Java for Beginners: A Crash Course to Learn Java Programming in 1 Week Rating: 5 out of 5 stars5/5Programming Arduino: Getting Started with Sketches Rating: 4 out of 5 stars4/5Learn SQL in 24 Hours Rating: 5 out of 5 stars5/5Learn JavaScript in 24 Hours Rating: 3 out of 5 stars3/5HTML in 30 Pages Rating: 5 out of 5 stars5/5Learn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5PYTHON: Practical Python Programming For Beginners & Experts With Hands-on Project Rating: 5 out of 5 stars5/5Python QuickStart Guide: The Simplified Beginner's Guide to Python Programming Using Hands-On Projects and Real-World Applications Rating: 0 out of 5 stars0 ratingsHTML & CSS: Learn the Fundaments in 7 Days Rating: 4 out of 5 stars4/5The Unofficial Guide to Open Broadcaster Software: OBS: The World's Most Popular Free Live-Streaming Application Rating: 0 out of 5 stars0 ratingsCoding All-in-One For Dummies Rating: 4 out of 5 stars4/5The Little SAS Book: A Primer, Sixth Edition Rating: 5 out of 5 stars5/5Python for Beginners: Learn the Fundamentals of Computer Programming Rating: 0 out of 5 stars0 ratingsLearn PowerShell in a Month of Lunches, Fourth Edition: Covers Windows, Linux, and macOS Rating: 0 out of 5 stars0 ratings
Reviews for Application Development with Swift
0 ratings0 reviews
Book preview
Application Development with Swift - Hossam Ghareeb
Table of Contents
Application Development with Swift
Credits
About the Author
About the Reviewers
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
Errata
Piracy
Questions
1. Hello Swift
Introduction to Swift
Playgrounds
The code structure
Arrays
Initializing an array
Iterating over arrays
Appending items
Removing and updating items
Dictionaries
Initializing a dictionary
Appending or updating values
Removing items from the dictionary
Enum
Using enumerations with the switch statement
Enumerations with associated values
Functions
Closures
Summary
2. Advanced Swift
Type casting and type checking
Downcasting
Using Any and AnyObject
Protocols
Properties
Methods
Class-only protocols
Protocol compositions
The protocol conformance
The optional requirements
Delegation
Extensions
Adding computed properties
Adding new initializers
Adding methods
Generics
Operator functions
Memory management
Using Objective-C and Swift in a single project
Importing Objective-C in the Swift project
Importing Swift in the Objective-C project
Limitations
Summary
3. Touch ID
What is Touch ID?
The LocalAuthentication framework
Summary
4. Introduction to HealthKit
What is HealthKit?
HealthKit limitations
HealthKit privacy
Getting started with HealthKit
Configuring the Xcode project
Getting your hands dirty with HealthKit
The HealthKit store
Asking for permissions
Updating the UI
Sharing data in the Health app
Summary
5. Introduction to Metal
What is Metal?
Features
3D rendering
Pipeline
Transformations
Projection
Other options to work with 3D rendering in iOS
Getting started with Metal
Devices and CAMetalLayers
The command queue
Vertex and color buffers
Vertex and fragment shaders
The render pipeline
The game loop and rendering
The display link
The render pass
The command buffer
Summary
6. Introduction to WatchKit
Apple watch
WatchKit
The WatchKit app
Glances
Actionable notifications
Working with WatchKit
Xcode targets
Interface controllers
Interface elements
Groups
Navigating interfaces
Presenting modally
Animation
Working with glances
Summary
7. Swift App Extensions
App extensions
Today
Share
Photo Editing
Document Provider
Understanding the Document Provider's lifecycle
The custom keyboard
Keyboard security
Keyboard settings
Working with the custom keyboard
Demo
Summary
Index
Application Development with Swift
Application Development with Swift
Copyright © 2015 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 author, 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: August 2015
Production reference: 1250815
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78528-817-3
www.packtpub.com
Credits
Author
Hossam Ghareeb
Reviewers
Tyler Hackbart
David Mattia
Hossam M. Sherif
Kenneth Strickland
Commissioning Editor
Julian Ursell
Acquisition Editor
Nikhil Karkal
Content Development Editor
Shali Deeraj
Technical Editor
Prajakta Mhatre
Copy Editor
Charlotte Carneiro
Project Coordinator
Kinjal Bari
Proofreader
Safis Editing
Indexer
Tejal Soni
Graphics
Sheetal Aute
Disha Haria
Production Coordinator
Melwyn D'sa
Cover Work
Melwyn D'sa
About the Author
Hossam Ghareeb is a software engineer who graduated from the computer and system engineering department of Alexandria University in 2012. Currently, he is an iOS software engineer at Prototype Interactive in Dubai. He has a lot of experience in iOS development and software engineering; he always keeps himself up to date with new technologies. It is his passion to help people by sharing his experience and writing tutorials to get people engaged quickly without problems. His favorite hobbies are fishing and playing video games, especially FIFA and PES. If you need his help or wish to go fishing with him, then you can contact him at <hossam.ghareb@gmail.com>.
I would like to thank each and every person who has been helpful to me, from my teaching staff to my friends. A special thanks to my lovely wife, Amira, for all her support and encouragement in spite of all the time this book kept me away from her. I thank my son, Yusuf, for inspiring me. I would also like to express my sincere gratitude toward my parents for teaching me how to be a good person.
Last but not least, I would like to thank the content editors, Shali Deeraj and Nikhil Karkal, for helping me and being nice to me, and the reviewers for their helpful comments and suggestions.
About the Reviewers
Tyler Hackbart is a web developer, designer, and technology enthusiast with a passion for everything in technology. Through self-learning, he gained the ability to write his first line of code when he was only 16 years old and has just started learning his sixth programming language. With his farm-raised work ethic, alongside a passion for crafting amazing user interactions and doing what he loves, Tyler has successfully worked in the technology field for 2 years. He is the cofounder of three start-ups and works in an application design firm, all based in Waterloo, Canada.
David Mattia is a student at the University of Notre Dame with a passion for software engineering. He has worked for General Electric Aviation and spends much of his free time doing freelance work.
Hossam M. Sherif is a software developer. He received his bachelor's degree in computer and system engineering from Alexandria University. He has spent several years in software development, especially in iOS and backend development. He has worked with many companies, such as Insidetrack, Inova LLC, and Log n Labs. He worked on different projects and in different roles, from software developer to team leader and manager. He served in the Egyptian Navy and participated in the enhancement and development of the IT department. He has certificates in software test processes and software test design. He participated in several volunteer projects and workshops as an instructor for Introduction to iOS Development,
a summer 2014 training course for undergraduates at Alexandria University, and also other courses, such as the Alexandria Startup 2012 weekend and IEEE ITW 2011.
Kenneth Strickland joined the US Army in 1986. After 4 years of active duty in the US Army, he came across software development. That was when he picked up his first C programming book and read it from cover to cover. Since then, he has never looked back.
He has been a software architect for over 10 years, and currently develops applications primarily in C/C++, Java, Objective-C, Swift, and .NET.
You can visit his website at http://kenster.guru.
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.
https://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
This book teaches you how to master the Swift programming language and use it in building apps with the new technologies introduced in iOS 8. Swift is a new programming language for iOS, OS X, and watchOS apps. In the beginning of this book, we will give you an advanced introduction to Swift, and then we will see how to apply this in real-app demos using the new technologies and APIs in iOS 8 such as TouchID, watchOS, Metal, and HealthKit.
What this book covers
Chapter 1, Hello Swift, gives a quick introduction and revision about Swift. This chapter is very important for Swift beginners and is highly recommended for Swift developers to revise their knowledge.
Chapter 2, Advanced Swift, boosts your Swift experience by allowing you to learn some advanced features in Swift. In this chapter, we will talk about protocols, extensions, and