Book Image

Mastering Swift

By : Jon Hoffman
Book Image

Mastering Swift

By: Jon Hoffman

Overview of this book

Table of Contents (22 chapters)
Mastering Swift
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using Cocoa data types


We have looked at several native Swift data types, such as the string, array, and dictionary types. While using these types is definitely preferred, as part of the Objective-C interoperability, Apple has provide convenient and effective ways to work with Cocoa data types from within our Swift applications.

Some of the Cocoa and Swift data types can be used interchangeably, others are automatically converted between Cocoa and Swift data types. Those data types that can be used interchangeably or converted are called bridged data types.

Swift also provides an overlay for working with foundation data types. This lets us work with foundation data types in a way that feels more like native Swift types. If we need to use these foundation data types, we need to add the following import statement to the top of the Swift file:

import Foundation

Let's take a look at how to work with some common Cocoa data types.

NSNumber

Swift will automatically bridge certain native numeric types...