Mastering Swift
eBook - ePub

Mastering Swift

Jon Hoffman

Condividi libro
  1. 358 pagine
  2. English
  3. ePUB (disponibile sull'app)
  4. Disponibile su iOS e Android
eBook - ePub

Mastering Swift

Jon Hoffman

Dettagli del libro
Anteprima del libro
Indice dei contenuti
Citazioni

Domande frequenti

Come faccio ad annullare l'abbonamento?
È semplicissimo: basta accedere alla sezione Account nelle Impostazioni e cliccare su "Annulla abbonamento". Dopo la cancellazione, l'abbonamento rimarrà attivo per il periodo rimanente già pagato. Per maggiori informazioni, clicca qui
È possibile scaricare libri? Se sì, come?
Al momento è possibile scaricare tramite l'app tutti i nostri libri ePub mobile-friendly. Anche la maggior parte dei nostri PDF è scaricabile e stiamo lavorando per rendere disponibile quanto prima il download di tutti gli altri file. Per maggiori informazioni, clicca qui
Che differenza c'è tra i piani?
Entrambi i piani ti danno accesso illimitato alla libreria e a tutte le funzionalità di Perlego. Le uniche differenze sono il prezzo e il periodo di abbonamento: con il piano annuale risparmierai circa il 30% rispetto a 12 rate con quello mensile.
Cos'è Perlego?
Perlego è un servizio di abbonamento a testi accademici, che ti permette di accedere a un'intera libreria online a un prezzo inferiore rispetto a quello che pagheresti per acquistare un singolo libro al mese. Con oltre 1 milione di testi suddivisi in più di 1.000 categorie, troverai sicuramente ciò che fa per te! Per maggiori informazioni, clicca qui.
Perlego supporta la sintesi vocale?
Cerca l'icona Sintesi vocale nel prossimo libro che leggerai per verificare se è possibile riprodurre l'audio. Questo strumento permette di leggere il testo a voce alta, evidenziandolo man mano che la lettura procede. Puoi aumentare o diminuire la velocità della sintesi vocale, oppure sospendere la riproduzione. Per maggiori informazioni, clicca qui.
Mastering Swift è disponibile online in formato PDF/ePub?
Sì, puoi accedere a Mastering Swift di Jon Hoffman in formato PDF e/o ePub, così come ad altri libri molto apprezzati nelle sezioni relative a Computer Science e Object Oriented Programming. Scopri oltre 1 milione di libri disponibili nel nostro catalogo.

Informazioni

Anno
2015
ISBN
9781784392154

Mastering Swift


Table of Contents

Mastering 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
Downloading the color images of this book
Errata
Piracy
Questions
1. Taking the First Steps with Swift
What is Swift?
Swift features
Playgrounds
Getting started with Playgrounds
iOS and OS X Playgrounds
Showing images in a Playground
Displaying graphs in Playgrounds
What Playgrounds are not
Swift language syntax
Comments
Semicolons
Parentheses
Curly braces
Assignment operator (=) does not return a value
Spaces are optional in conditional and assignment statements
Hello world
Summary
2. Learning about Variables, Constants, Strings, and Operators
Constants and variables
Defining constants and variables
Type safety
Type inference
Explicit types
Numeric types
Integers
Floating-point
The Boolean type
The string type
Optional variables
Enumerations
Operators
The assignment operator
Comparison operators
Arithmetic operators
The remainder operator
Increment and decrement operators
Compound assignment operators
The ternary conditional operator
The logical NOT operator
The logical AND operator
The logical OR operator
Summary
3. Using Collections and Cocoa Data Types
Swift collection types
Mutability
Arrays
Creating and initializing arrays
Accessing the array elements
Counting the elements of an array
Is the array empty?
Appending to an array
Inserting a value into an array
Replacing elements in an array
Removing elements from an array
Adding two arrays
Reversing an array
Retrieving a subarray from an array
Making bulk changes to an array
Algorithms for arrays
sort
sorted
filter
map
Iterating over an array
Dictionaries
Creating and initializing dictionaries
Accessing dictionary values
Counting key/values in a dictionary
Is the dictionary empty?
Updating the value of a key
Adding a key-value pair
Removing a key-value pair
Tuples
Using Cocoa data types
NSNumber
NSString data type
NSArray
NSDictionary
Foundation data types
Summary
4. Control Flow and Functions
What we have learned so far
Curly brackets
Parentheses
Control flow
Conditional statements
The if statement
Executing codes with the if-else statement
The for loops
Using the for loop variant
Using the for-in loop variant
The while loop
Using the while loop
Using the do-while loop
The switch statement
Control transfer statements
The continue statement
The break statement
The fallthrough statement
Functions
Using a single parameter function
Using a multiparameter function
Defining a parameter's default values
Returning multiple values from a function
Returning optional values
Adding external parameter names
Using shorthand for external parameter names
Using variadic parameters
Parameters as variables
Using inout parameters
Nesting functions
Summary
5. Classes and Structures
What are classes and structures?
Similarities between classes and structures
Differences between classes and structures
Value versus reference types
Creating a class or structure
Properties
Stored properties
Computed properties
Property observers
Methods
Initializer
Internal and external parameter names
Failable initializers
Inheritance
Overriding methods and properties
Overriding methods
Overriding properties
Preventing overrides
Protocols
Protocol syntax
Property requirements
Method requirements
Optional requirements
Extensions
Memory management
Reference versus value types
The working of ARC
Strong reference cycles
Summary
6. Working with XML and JSON Data
XML and JSON
Common files
XML and the NSXMLParser class
Using the NSXMLParserDelegate protocol
Parsing XML documents
XML and NSXMLDocument
XML and manually building XML documents
JSON and NSJSONSerialization
Parsing a JSON document
Creating a JSON document
Summary
7. Custom Subscripting
Introducing subscripts
Subscripts with Swift arrays
Read and write custom subscripts
Read only custom subscripts
Calculated subscripts
Subscript values
Subscripts with ranges
External names for subscripts
Multidimensional subscripts
When not to use a custom subscript
Summary
8. Using Optional Type and Optional Chaining
Introducing optionals
The need for optional types in Swift
Defining an optional
Using optionals
Unwrapping an optional
Optional binding
Returning optionals from functions, methods, and subscripts
Using optionals as a parameter in a function or method
Optional types with tuples
Optional chaining
The nil coalescing operator
Summary
9. Working with Generics
Introduction to generics
Generic functions
Generic types
Associated types
Summary
10. Working with Closures
Introducing closures
Simple closures
Shorthand syntax for closures
Using closures with Swift's array algorithms
Standalone closures and good style guidelines
Changing functionality
Select a closure based on results
Strong reference cycles with closures
Summary
11. Using Mix and Match
What is mix and match?
Using Swift and Objective-C together in the same project
Creating the project
Adding the Swift file to the Objective-C project
The Objective-C bridging header file part 1
Adding the Objective-C file to the project
The Messages Objective-C class
The Objective-C bridging header file part 2
The MessageBuilder Swift class – accessing Objective-C code from Swift
The Objective-C class – accessing Swift code from Objective-C
Summary
12. Concurrency and Parallelism in Swift
Concurrency and parallelism
Grand Central Dispatch
Creating and managing dispatch queues
Creating queues with the dispatch_queue_create() function
Creating concurrent dispatch queues with the dispatch_queue_create() function and using the dispatch_asynch() function
Creating a serial dispatch queue with the dispatch_queue_create() function and using the dispatch_sync() function
Requesting concurrent queues with the dispatch_get_global_queue() function
Requesting the main queue with the dispatch_get_main_queue() function
Using the dispatch_after() function
Using the dispatch_once() function
Using NSOperation and NSOperationQueue types
Using the NSBlockOperation implementation of NSOperation
Using the addOperationWithBlock() method of the operation queue
Subclassing the NSOperation class
Summary
13. Swift Formatting and Style Guide
What is a programming style guide?
Your style guide
Do not use semicolons at the end of statements
Do not use parentheses for conditional statements
Naming
Classes
Functions and methods
Constants and variables
Indenting
Comments
Using the self keyword
Types
Constants and variables
Opt...

Indice dei contenuti