Foundation data types

When using Foundation data types, Swift provides an overlay that makes interacting with them feel like they are native Swift types. We use this overlay to interact with Foundation types, such as CGSize and CGRect for iOS applications (NSSize and NSRect for OS X applications). When developing iOS or OS X applications, we will interact with Foundation data types on a regular basis, so it is good to see this overlay in action.

Let's look at how to initialize some Foundation data types. The following example defines NSRange, CGRect, and NSSize:

var range = NSRange(location: 3, length: 5)
var rect = CGRect(x: 10, y: 10, width: 20, height: 20)
var size = NSSize(width: 20, height: 40)

The overlay also lets us access the properties ...

Get Swift: Developing iOS Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.