Swift High Performance
eBook - ePub

Swift High Performance

  1. 212 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Swift High Performance

Book details
Book preview
Table of contents
Citations

About This Book

Leverage Swift and enhance your code to take your applications to the next level

About This Book

  • Build solid, high performance applications in Swift
  • Increase your efficiency by getting to grips with concurrency and parallel programming
  • Use Swift to design performance-oriented solutions

Who This Book Is For

This book is aimed at experienced Swift developers wanting to optimize their programs on Apple platforms to optimize application performance.

What You Will Learn

  • Build solid, stable, and reliable applications using Swift
  • Use REPL and Pl to manage and configure relational databases
  • Explore Swift's features including its static type system, value objects, and functional programming Design reusable code for high performance in Swift
  • Use to Xcode LLBD and REPL to debug commands
  • Avoid sharing resources by using concurrency and parallel programming
  • Understand the lazy loading pattern, lazy sequences, and lazy evolution.

In Detail

Swift is one of the most popular and powerful programming languages for building iOS and Mac OS applications, and continues to evolve with new features and capabilities. Swift is considered a replacement to Objective-C and has performance advantages over Objective-C and Python. Swift adopts safe programming patterns and adds modern features to make programming easier, more flexible, and more fun.

Develop Swift and discover best practices that allow you to build solid applications and optimize their performance.

First, a few of performance characteristics of Swift will be explained. You will implement new tools available in Swift, including Playgrounds and REPL. These will improve your code efficiency, enable you to analyse Swift code, and enhance performance. Next, the importance of building solid applications using multithreading concurrency and multi-core device architecture is covered, before moving on to best practices and techniques that you should utilize when building high performance applications, such as concurrency and lazy-loading. Finally, you will explore the underlying structure of Swift further, and learn how to disassemble and compile Swift code.

Style and approach

This is a comprehensive guide to enhancing Swift programming techniques and methodology to enable faster application development.

Frequently asked questions

Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes, you can access Swift High Performance by Kostiantyn Koval in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming Mobile Devices. We have over one million books available in our catalogue for you to explore.

Information

Year
2015
ISBN
9781785282201
Edition
1

Swift High Performance


Table of Contents

Swift High Performance
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. Exploring Swift's Power and Performance
Swift speed
Welcome to Swift
Why should I learn Swift?
Swift's features and benefits
Clean and beautiful
No semicolons
Type inference
Other clean code Swift features
A clean code summary
Safe
Optionals
Error handling
Rich type system
Powerful value types
A multiparadigm language
Object oriented
Protocol oriented
Functional
Generic purpose
Fast
Swift interoperability
Using Objective-C in Swift
Setup
The application target
The framework target
Calling Objective-C code
Using Swift in Objective-C
Features of Swift that are not available in Objective-C
Performance – meaning and key metrics
Everyday code performance
The importance of performance
The key metrics
Summary
2. Making a Good Application Architecture in Swift
Making a Swift application
The differences between variables and constants
Immutability
Multithreading
Value types and immutability
Reference types
Value types
The power of structures
Representing the state with classes
Representing the absence of values with optionals
Optional and non-optional types
Safe nil handling
Using optionals
Wrapping up on optionals
Functional programming
Function types
Splitting the code
The closure expression
Type inference
Implicit return type
Shorthand argument names
Trailing closure syntax
The standard library
The map method
map for optionals
The reduce method
The filter method
Generics
Generic functions
Type constraints
The generic type and collections
Safety
Dangerous operations
Summary
3. Testing and Identifying Slow Code with the Swift Toolkit
REPL
Playgrounds
Interactive documentation
The folder structure
The source folder
Resources
Pages
XCPlayground
LLDB
REPL in Xcode
Console logs
Performance measuring in unit tests
Instruments
A reminder
Summary
4. Improving Code Performance
Understanding performance optimization
Explicit
Implicit
Optimization checklist
Swift code compilation
Constants and variables
Method calls
Functions and methods
Global functions
Type methods
Static methods
Instance methods
Comparing function speed
Functions and methods usage summary
Intelligent code
Dangerous functions
Console print
Removing print logs
Comment out
Using build configurations
Using nonoptimizable constants
Improving speed
Final
Inline functions
Value objects and reference objects
Memory allocation
Swift arrays and unsafe C arrays
Function parameters
Creating a pointer to an existing variable
Allocating memory for the pointer
Comparing Swift arrays with unsafe C arrays
A summary of working with pointers
Avoiding Objective-C
Avoiding exposing Swift to Objective-C
Dynamic
A summary of avoiding Objective-C
Summary
5. Choosing the Correct Data Structure
An overview of data structures
Collection types
Swift standard library collections
Arrays
Using arrays
Fast operations
Slower operations
Search
Sort
Sets
Using sets
Set operations
Dictionaries
Collection memory allocation
Empty
Reserve capacity
Default values
The CollectionType protocol methods
Protocol extensions
Accelerate and Surge
Other collections
Summary
6. Architecting Applications for High Performance
Achieving high performance
Device architecture
Concurrency overview
Threads
Thread complexity
Solution for threads
GCD
Queues
Main queues
Concurrent queues
Own queues
Tasks
Adding tasks to the queue
Synchronous dispatch
Asynchronous dispatch
Operation queues
Designing asynchronous code
Avoiding state
Capture list
Immutable state
Divide and conquer
Controlling the lifetime
Applying the @autoclosure and @noescape attributes
@autoclosure
@noescape
@autoclosure (escaping)
Summary
7. The Importance of Being Lazy
The lazy mindset
Separation
Do work on demand
Approximate results
Lazy loading
Global constants and variables
Type properties
Lazy properties
Computed properties
Lazy collections and evaluation
Sequences and collections
Sequences
Collections
Implementing our own sequence and collection
Using lazy
Using the lazy sequence
Using a lazy collection
Summary
8. Discovering All the Underlying Swift Power
How Swift is so fast
Swift command line tools
xcrun
The Swift compiler
swift
swiftc
The Swift compilation process and swiftc
Swift AST
SIL
LLVM IR
Other swiftc options
Analyzing executable files
Summary
Final thoughts
Index

Swift High Performance

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 ind...

Table of contents

  1. Swift High Performance