Learning Swift
eBook - ePub

Learning Swift

Andrew J Wagner

Buch teilen
  1. 266 Seiten
  2. English
  3. ePUB (handyfreundlich)
  4. Über iOS und Android verfügbar
eBook - ePub

Learning Swift

Andrew J Wagner

Angaben zum Buch
Buchvorschau
Inhaltsverzeichnis
Quellenangaben

Häufig gestellte Fragen

Wie kann ich mein Abo kündigen?
Gehe einfach zum Kontobereich in den Einstellungen und klicke auf „Abo kündigen“ – ganz einfach. Nachdem du gekündigt hast, bleibt deine Mitgliedschaft für den verbleibenden Abozeitraum, den du bereits bezahlt hast, aktiv. Mehr Informationen hier.
(Wie) Kann ich Bücher herunterladen?
Derzeit stehen all unsere auf Mobilgeräte reagierenden ePub-Bücher zum Download über die App zur Verfügung. Die meisten unserer PDFs stehen ebenfalls zum Download bereit; wir arbeiten daran, auch die übrigen PDFs zum Download anzubieten, bei denen dies aktuell noch nicht möglich ist. Weitere Informationen hier.
Welcher Unterschied besteht bei den Preisen zwischen den Aboplänen?
Mit beiden Aboplänen erhältst du vollen Zugang zur Bibliothek und allen Funktionen von Perlego. Die einzigen Unterschiede bestehen im Preis und dem Abozeitraum: Mit dem Jahresabo sparst du auf 12 Monate gerechnet im Vergleich zum Monatsabo rund 30 %.
Was ist Perlego?
Wir sind ein Online-Abodienst für Lehrbücher, bei dem du für weniger als den Preis eines einzelnen Buches pro Monat Zugang zu einer ganzen Online-Bibliothek erhältst. Mit über 1 Million Büchern zu über 1.000 verschiedenen Themen haben wir bestimmt alles, was du brauchst! Weitere Informationen hier.
Unterstützt Perlego Text-zu-Sprache?
Achte auf das Symbol zum Vorlesen in deinem nächsten Buch, um zu sehen, ob du es dir auch anhören kannst. Bei diesem Tool wird dir Text laut vorgelesen, wobei der Text beim Vorlesen auch grafisch hervorgehoben wird. Du kannst das Vorlesen jederzeit anhalten, beschleunigen und verlangsamen. Weitere Informationen hier.
Ist Learning Swift als Online-PDF/ePub verfügbar?
Ja, du hast Zugang zu Learning Swift von Andrew J Wagner im PDF- und/oder ePub-Format sowie zu anderen beliebten Büchern aus Ciencia de la computación & Programación. Aus unserem Katalog stehen dir über 1 Million Bücher zur Verfügung.

Information

Jahr
2015
ISBN
9781784392505

Learning Swift


Table of Contents

Learning Swift
Credits
About the Author
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
Errata
Piracy
Questions
1. Introducing Swift
Defining our goals for this book
Setting up the development environment
Running our first Swift code
Understanding playgrounds
Learning with this book
Summary
2. Building Blocks – Variables, Collections, and Flow Control
Core Swift types
Constants and variables
Containers
Tuples
Arrays
Dictionaries
Swift's type system
Printing on the console
Control flow
Conditionals
Switches
Loops
Functions
Basic functions
Parameterized functions
Functions that return values
Functions with default arguments
Bringing it all together
Summary
3. One Piece at a Time – Types, Scopes, and Projects
Structs
Types versus instances
Properties
Member and static methods
Computed properties
Reacting to property changes
Subscripts
Custom initialization
Classes
Inheriting from another class
Initialization
Overriding initializers
Required initializers
Designated and convenience initializers
Overriding methods and computed properties
Methods
Computed properties
Casting
Upcasting
Downcasting
Enumerations
Basic declaration
Testing enumeration values
Raw values
Associated values
Methods and properties
Projects
Setting up a command-line Xcode project
Creating and using an external file
Interfacing with code from other files
File organization and navigation
Extensions
Scope
How is scope defined
Nested types
Access control
Summary
4. To Be or Not to Be – Optionals
Introducing optionals
Unwrapping an optional
Optional binding
Forced unwrapping
Nil coalescing
Optional chaining
Implicitly unwrapped optionals
Debugging optionals
The underlying implementation
Summary
5. A Modern Paradigm – Closures and Functional Programming
Functional programming philosophy
State and side effects
Declarative versus imperative code
Closures
Closures as variables
Closures as parameters
Syntactic sugar
Building blocks of functional programming in Swift
The filter function
The reduce function
The map function
The sorted function
How these affect the state and nature of code
Lazy evaluation
Curried functions
Summary
6. Make Swift Work for You – Protocols and Generics
Protocols
Defining a protocol
Implementing a protocol
Using type aliases
Defining a generic
The generic function
The generic type
Type constraints
Protocol constraints
Where clauses for protocols
Where clauses for equality
Extending the existing generics
Enhancing arrays
Enhancing dictionaries
Putting protocols and generics to use
Generators
Sequences
Product of Fibonacci numbers under 50
Summary
7. Everything is Connected – Memory Management
How data is stored in a computer
Filesystem
Memory
Value types versus reference types
Determining a value or reference type
Behavior on assignment
Behavior on input
Capturing behavior of closure
Automatic reference counting
Object relationships
Strong relationships
Weak relationships
Unowned relationships
Strong reference cycles
Strong reference cycles between objects
Spotting
Fixing the cycles
With closures
Spotting
Fixing
Lost objects
Between objects
With closures
Summary
8. Writing Code the Swift Way – Design Patterns and Techniques
What is a design pattern?
Behavioral patterns
The iterator pattern
The observer pattern
The callback property
The notification center
Structural patterns
The composite pattern
Hierarchies
An alternative to subclassing
The delegate pattern
Model-View-Controller
Creational patterns
A singleton/shared instance
The abstract factory pattern
Using associated values effectively
Replacing class hierarchies
Concisely representing a state
Extending system types to reduce code
Lazy properties
Avoiding unnecessary memory usage
Avoiding unnecessary processing
Localizing logic to the concerned property
Summary
9. Harnessing the Past – Understanding and Translating Objective-C
Swift's relationship with Objective-C
The history of Objective-C
Constants and variables
Value types
Reference types
Containers
Arrays
Dictionaries
Control flow
Conditionals
Switches
Loops
Functions
Types
Structures
Enumerations
Classes
The basic class
Initializers
Properties
Methods
Inheritance
Categories
Protocols
Blocks
Projects
Header files
An implementation file
Organization
Calling Objective-C code from Swift
A bridging header
Using functions
Using types
Containers
Reference type translation
Summary
10. A Whole New World – Developing an App
Conceptualizing the app
Features
The interface
Data
Setting up the app project
Configuring the user interface
Running the app
Allowing picture taking
Temporarily saving a photo
Populating our photo grid
Refactoring to respect Model-View-Controller
Permanently saving a photo
Summary
11. What's Next? Resources, Advice, and Next Steps
Apple's documentation
Forums and blogs
Blog posts
Forums
Prominent figures
Podcasts
Summary
Index

Learning 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: June 2015
Production reference: 1250615
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78439-250-5
www.packtpub.com

Credits

Author
Andrew J Wagner
Reviewers
Giordano Scalzo
Cory Bohon
Commissioning Editor
Sarah Crofton
Acquisition Editors
Vivek Anantharaman
Richard Brookes-Bland
Content Development Editor
Kirti Patil
Technical Editor
Mrunmayee Patil
Copy Editors
Pranjali Chury
Neha Vyas
Project Coordinator
Nidhi Joshi
Proofreader
Safis Editing
Indexer
Mariammal Chettiyar
Graphics
Disha Haria
Production Coordinator
Nilesh R. Mohite
Cover Work
Nilesh R. Mohite

About the Author

Andrew J Wagner is an independent software developer who concentrates on iOS development and backend web services and has a degree in computer engineering from Rensselaer Polytechnic Institute, New York. He has also been developing his own iOS apps through his company, Learn Brigade LLC, since 2008 and has experience working with and for large-scale companies and small-scale companies. He is passionate about using computers as a creative outlet and writing software that is beautiful in implementation, functionality, and experience.

About the Reviewer

Giordano Scalzo has been a developer since the days of the ZX Spectrum.
He wor...

Inhaltsverzeichnis