Use bridged Foundation types in your Swift codebase to work with dates, times, and other values.
When importing the Foundation framework, the Swift overlay provides value types for many bridged reference types. Many other types are renamed or nested to clarify relationships.
Prefer Swift Value Types to Bridged Objective-C Reference Types
The value types in the table below have the same functionality as their corresponding reference types. Class clusters that include immutable and mutable subclasses, like
NSMutable, are bridged to a single value type.
Swift value type
Objective-C reference type
Swift numeric types (
When Swift code imports Objective-C APIs, the importer replaces Foundation reference types with their corresponding value types. For this reason, you should almost never need to use a bridged reference type directly in your own code.
If you need the reference semantics that come with the Foundation reference type, you can access it with its original
NS class name prefix. Cast between a Swift value type and its corresponding reference type by using the
Note Renamed Reference Types
For Foundation types that aren't bridged to value types, the Swift overlay renames classes and protocols, as well as related enumerations and constants. These types and protocols drop their
NS prefix, with the following exceptions:
Classes specific to Objective-C or inherently tied to the Objective-C runtime, like
Platform-specific classes, like
Foundation classes often declare enumeration or constant types. When importing these types, Swift moves them to be nested types of their related types. For example, the
NSJSONReading option set is imported as