-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Swift 4 Programming Cookbook

In Objective-C, all objects are at the top level, and given global scope, they can be said to be in the same namespace. This is one reason for the convention among Objective-C developers, including Apple, to prefix their class names with two-or-three letter identifiers.
These prefix characters allow similarly named classes from different frameworks to be differentiated, for example, UIView from UIKit and SKView from SpriteKit. Swift solves this problem by allowing types to be nested within other types, providing namespacing with nested types and modules.
Any type can be defined as being nested within another type. This allows us to tightly associate one type with another, in addition to providing namespacing, which helps differentiate types with the same name.
In Swift 3, only types that didn't use generics could be nested within another type, or have a nested type within it. This limitation was removed with Swift 4.
Let's build a system to monitor...