Swift 2 By Example - Giordano Scalzo - E-Book

Swift 2 By Example E-Book

Giordano Scalzo

0,0
39,59 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Create robust and extensible iOS apps using the advanced features of Swift 2

About This Book

  • Get up to speed with the new features of Swift 2 by following the exhaustive examples in this book
  • Specialize in developing real iOS apps, and 2D and 3D videogames using Swift and Cocoapods
  • Learn how to build server API apps to feed your iOS client apps

Who This Book Is For

This book is ideal for those who want to learn to develop app in Swift, starting the right way. Whether you are an expert Objective-C programmer or are new to this platform, you'll quickly grasp the code of real world apps, and discover how to use Swift effectively. Prior experience in development for Apple devices would be helpful, but is not mandatory.

What You Will Learn

  • Create a server in Swift to deliver JSON data to an iOS app
  • Take advantage of Cocoapods to use third-party libraries
  • Use a clean and effective architecture to decrease complexity and speed up development
  • Take advantage of the most useful parts of the iOS SDK
  • Build games with SpriteKit and SceneKit
  • Develop an app running on the cloud to act as an API server for your client's apps

In Detail

Swift is no longer the unripe language it was when launched by Apple at WWDC14, now it's a powerful and ready-for-production programming language that has empowered most new released apps.

Swift is a user-friendly language with a smooth learning curve; it is safe, robust, and really flexible.

Swift 2 is more powerful than ever; it introduces new ways to solve old problems, more robust error handling, and a new programming paradigm that favours composition over inheritance.

Swift 2 by Example is a fast-paced, practical guide to help you learn how to develop iOS apps using Swift. Through the development of seven different iOS apps and one server app, you'll find out how to use either the right feature of the language or the right tool to solve a given problem.

We begin by introducing you to the latest features of Swift 2, further kick-starting your app development journey by building a guessing game app, followed by a memory game. It doesn't end there, with a few more apps in store for you: a to-do list, a beautiful weather app, two games: Flappy Swift and Cube Runner, and finally an ecommerce app to top everything off.

By the end of the book, you'll be able to build well-designed apps, effectively use AutoLayout, develop videogames, and build server apps.

Style and approach

These easy-to-follow tutorials show you how to build real-world apps. The difficulty and complexity level increases chapter by chapter. Each chapter is dedicated to build a new app, beginning from a basic and unstyled app through to a full 3D game. The last two chapters show you how to build a complete client-server ecommerce app right from scratch.

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 282

Veröffentlichungsjahr: 2016

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Swift 2 By Example
Credits
About the Author
About the Reviewer
www.PacktPub.com
eBooks, discount offers, and more
Why subscribe?
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. Welcome to the World of Swift
The first look at Swift
Let's go to the playground
The building blocks – variables and constants
Collecting variables in containers
Controlling the flow
Transforming the values using functions
Structs – custom compound types
Classes – common behavior objects
Loose coupling with protocols
Composing objects using protocol extensions
Checking the existence of an optional value
Enumerations on steroids
Extended pattern matching
Catching errors
Swift functional programming patterns
Summary
2. Building a Guess the Number App
The app is…
Building a skeleton app
Adding the graphics components
Connecting the dots
Adding the code
Summary
3. A Memory Game in Swift
The app is…
Building the skeleton of the app
The menu screen
Implementing the basic menu screen
Creating a nice menu screen
The game screen
The structure
Adding a collection view
Sizing the components
Connecting the dataSource and the delegate
Implementing a deck of cards
What we are expecting
The card entity
Crafting the deck
Shuffling the deck
Finishing the deck
Put the cards on the table
Adding the assets
The CardCell structure
Handling touches
Finishing the game
Implementing the game logic
We got a pair
We made the wrong move
Et voilà! The game is completed
Summary
4. A TodoList App in Swift
The app is…
Building a skeleton app
Implementing an empty app
Adding third-party libraries with CocoaPods
Implementing the Todos view controller
Building the Todos screen
Adding entities
Implementing datastore
Connecting datastore and View Controller
Configuring tableView
Finishing touches
Swipe that cell!
Adding a Todo task
The add a Todo view
The add a Todo View Controller
Finishing TodoDatastore
List View Controller
Where do we go from here?
Summary
5. A Pretty Weather App
The app is…
Building the skeleton
Creating the project
Adding assets
Implementing the UI
The UI in blocks
Completing the UI
Implementing CurrentWeatherView
Building WeatherHourlyForecastView
Seeing the next day's forecast in WeatherDaysForecastView
Blurring the background
Downloading the background image
Searching in Flickr
Geolocalising the app
Using Core Location
Retrieving the actual forecast
Getting the forecast from OpenWeatherMap
Rendering CurrentWeatherView
Rendering WeatherHourlyForecastView
Rendering WeatherDaysForecastView
Connecting to the server
Where do we go from here?
Summary
6. Flappy Swift
The app is…
Building the skeleton of the app
Creating the project
Implementing the menu
A stage for a bird
SpriteKit in a nutshell
Explaining the code
Simulating a three-dimensional world using parallax
How to implement scrolling
A flying bird
Adding the Bird node
Making the bird flap
Pipes!
Implementing the pipes node
Making the components interact
Setting up the collision-detection engine
Completing the game
Colliding with pipes
Adding the score
Adding a restart pop-up
Summary
7. Polishing Flappy Swift
Adding juiciness
Let there be sounds!
Playing the soundtrack
Shaking the screen!
Integrating with Game Center
What Game Center provides
Setting up Game Center
Creating an app record on iTunes Connect
Enabling Game Center
Creating fake user accounts to test Game Center
Authenticating a player
Summary
8. Cube Runner
The app is…
Introduction to SceneKit
What is SceneKit?
Building an empty scene
Adding a green torus
Let there be light!
Let's make it move!
Implementing Cube Runner
The game skeleton
Implementing the menu
Flying in a 3D world
Setting up a scene
Adding a fighter
Texturing the world
Make it move
Adding cubes
Adding more obstacles
Adding a few touches
The score
Let's add music
Summary
9. Completing Cube Runner
Creating a real game
Detecting collisions
Game over!
Adding the juice
Game Center
Summary
10. ASAP – an E-commerce App in Swift
The app is…
The first requirement: login and registration
The second requirement: the products grid
The third requirement: the open cart
The skeleton app and register screen
The skeleton app
The ASAP e-commerce store
The e-commerce product list
The product cell
Parsing and storing products
The ASAP cart
Adding a product to the cart
Removing items from cart and checkout
Summary
11. ASAPServer, a Server in Swift
The interface of the ASAP Server
One skeleton server for two OSes
An OS X skeleton server
Preparing the OS X environment
The HelloWorld skeleton server
Preparing the Linux environment
The ASAPServer
The Products
The cart
The order
Connecting the ASAP app
The products
The Cart
The order
Summary
Index

Swift 2 By Example

Swift 2 By Example

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 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: March 2016

Production reference: 1080316

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-78588-292-0

www.packtpub.com

Credits

Author

Giordano Scalzo

Reviewer

Hugo Solis

Commissioning Editor

Veena Pagare

Acquisition Editor

Reshma Raman

Content Development Editor

Divij Kotian

Technical Editor

Vishal Mewada

Copy Editor

Stuti Srivastava

Project Coordinator

Nikhil Nair

Proofreader

Safis Editing

Indexer

Tejal Daruwale Soni

Production Coordinator

Manu Joseph

Cover Work

Manu Joseph

About the Author

Giordano Scalzo is a developer with 20 years of programming experience, since the days of the ZXSpectrum.

He has worked in C++, Java, .Net, Ruby, Python, and in so many other programming languages he has forgotten the names.

After years of backend development, over the past 5 years Giordano has developed extensively for iOS, releasing more than 20 apps—apps that he wrote for clients, enterprise applications, or on his own.

Currently, he is a contractor in London, where—through his company, Effective Code Ltd, http://effectivecode.co.uk—he delivers code for iOS, aiming at quality and reliability.

In his spare time, when he is not crafting retro game clones for iOS, he writes his thoughts at http://giordanoscalzo.com.

I'd like to thank my better half, Valentina, who lovingly supports me in everything I do: without you, none of this would have been possible.

Thanks to my bright future, Mattia and Luca, for giving me lots of smiles and hugs when I needed them.

Finally, my gratitude goes to my Mum and Dad, who gave my curiosity the right push, along with the support to follow my passions, which began the day they bought me a ZXSpectrum.

About the Reviewer

Hugo Solis is an assistant professor in the Physics department at the University of Costa Rica. His current research interests are computational cosmology, complexity and the influence of hydrogen on material properties. He has wide experience with languages including C/C++ and Python for scientific programming and visualization. He is a member of the Free Software Foundation, and he has contributed code to some free software projects. He has also been a technical reviewer for Mastering Object-oriented Python, Learning Object-oriented Programming, and Kivy: Interactive Applications in Python and is the author of Kivy Cookbook, Packt Publishing. Currently, he is in charge of the Institute of Food Technologists, a Costa Rican scientific nonprofit organization for the multidisciplinary practice of Physics (http://iftucr.org).

I'd like to thank Katty Sanchez, my beloved mother, for her support and cutting-edge thoughts.

www.PacktPub.com

eBooks, discount offers, and more

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 <[email protected]> for more details.

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 PacktCopy and paste, print, and bookmark contentOn demand and accessible via a web browser

Preface

The introduction of Swift during WWDC 2014 surprised the whole community of iOS developers, who were waiting to be introduced to the new API from iOS 8, not to be transformed into beginners.

Besides the surprise, most of them understood that this would have been a great opportunity to create a new world of libraries, patterns, best practices, and so on. On the other hand, communities of programmers in different languages, who were intimidated by the rough first impact of Objective-C, started to be attracted by Swift, which—with its friendly syntax—was less intimidating.

After a year, Swift 2.0 has proven to be a huge improvement over the first version, enriched by a lot of new features and strengthened by its use in thousands of new apps. It is finally ready for production!

In WWDC 2015, Apple made another surprising announcement: Swift will be open source and there will be versions for different operating systems, beginning with Linux and Windows. This opens up a whole new scenario, where it will be possible to implement both client and the server apps with the same language.

This book will introduce you the world of app development using the new features in Swift 2, and it will show you how to build Linux apps in Swift in order to create server counterparts of your mobile apps.

Through simple step-by-step chapters, the book will teach you how to build both utility and game apps; while building them, you'll learn the basics of Swift and iOS.

What this book covers

Chapter 1, Welcome to the World of Swift, introduces the Swift syntax and the most important features provided by the language.

Chapter 2, Building a Guess the Number App, introduces Xcode, its project file, and the different editors required to build an app; a simple game app will be created to demonstrate these.

Chapter 3, A Memory Game in Swift, shows the creation of a complete game app, with images and animations, without using any Game framework but with only the fundamental iOS libraries.

Chapter 4, A TodoList App in Swift, teaches you how to create a real-world utility app, handling the library dependencies with Cocoapods.

Chapter 5, A Pretty Weather App, shows you how to create a nice looking app that retrieves data from third-party servers.

Chapter 6, Flappy Swift, covers SpriteKit, the 2D iOS game engine.

Chapter 7, Polishing Flappy Swift, completes the game, adding Game Center support and various entertaining touches.

Chapter 8, Cube Runner, covers SceneKit and 3D programming, implementing a 3D endless runner with a space theme.

Chapter 9, Completing Cube Runner, finalizes the game and adds Game Center support.

Chapter 10, ASAP – an E-commerce App in Swift, implements an ecommerce app that uses local storage to store the products.

Chapter 11, ASAPServer, a Server in Swift, is a follow-up to the previous chapter, where we'll implement a backend server for Linux to handle the requests of the ASAP e-commerce app.

What you need for this book

In order to get the most out of this book, there are a few essentials you will need:

A Mac computer running OS X 10.11.2 or higherA basic knowledge of programmingXcode 7.2 or higherAn iPhone 5s or higher (an app uses CoreMotion that doesn't work in the simulator)

Who this book is for

This book is ideal for those who want to learn how to develop apps in Swift, starting the right way. Whether you are an expert Objective-C programmer or are new to this platform, you'll quickly grasp the code for real-world apps and discover how to use Swift effectively. Prior experience in the development of Apple devices would be helpful, but it is not mandatory.

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 for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

Log in or register to our website using your e-mail address and password.Hover the mouse pointer on the SUPPORT tab at the top.Click on Code Downloads & Errata.Enter the name of the book in the Search box.Select the book for which you're looking to download the code files.Choose from the drop-down menu where you purchased this book from.Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

WinRAR / 7-Zip for WindowsZipeg / iZip / UnRarX for Mac7-Zip / PeaZip for Linux

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from http://www.packtpub.com/sites/default/files/downloads/Swift2byExample_ColorImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at <[email protected]> with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at <[email protected]>, and we will do our best to address the problem.