Book Image

Swift High Performance

By : Kostiantyn Koval
Book Image

Swift High Performance

By: Kostiantyn Koval

Overview of this book

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.
Table of Contents (15 chapters)
Swift High Performance
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Swift standard library collections


You will very often be using different collections to store and process data in your applications. Swift has three different built-in collection types: arrays, dictionaries, and sets.

The Swift standard library also has many functions for working with these collections, such as sort, find, filter, map, and many others. These functions have very efficient implementations, and you should use them instead of making your own. First, let's take a look at the different collections.

Arrays

An array is an ordered collection of values that provides access to its elements by indexes. It is a very simple and well-known collection. You would use an array in these situations:

  • Simple element storage (often add/remove from the end)

  • Elements need to be ordered

  • Random access to elements

Arrays are usually implemented as a continuous block of memory in which you store values. Because memory blocks are usually located next to each other, access to elements can usually be transformed...