Book Image

Beginning Swift

By : Rob Kerr, Kåre Morstøl
Book Image

Beginning Swift

By: Rob Kerr, Kåre Morstøl

Overview of this book

Take your first foray into programming for Apple devices with Swift.Swift is fundamentally different from Objective-C, as it is a protocol-oriented language. While you can still write normal object-oriented code in Swift, it requires a new way of thinking to take advantage of its powerful features and a solid understanding of the basics to become productive.
Table of Contents (10 chapters)


A set is an unordered collection of unique elements. It can very efficiently add, remove, or check if it contains a specific element (on average O(1), meaning it takes the same time regardless of the size of the set), in contrast to an unsorted array, where these operations take O(n) (the array may need to access and/or move most of its element).

Sets can be used for tracking which part of a custom view should be hidden, like which parts of an outline view are collapsed. When displaying the view, you would only show the children of those nodes which are not in the collapsed set. So, you are in a sense adding a Bool property to types you do not control. Sets can also be used for removing duplicates; you just add a sequence to an empty set and all duplicates will be gone.

Set implements these protocols:

  • Equatable means you can check if instances are equal with a == b or not equal with a != b. Each type defines for itself what ...