user6451264
user6451264

Reputation:

What does importing Foundation do to String?

When I import Foundation, all of a sudden String objects (among others) are able to do a bunch of things they didn’t before. How does this feature work? Are there any downsides to it? Will it change the behavior of code I wrote before adding the import?

Upvotes: 2

Views: 153

Answers (1)

jtbandes
jtbandes

Reputation: 118681

The NSString class from Foundation is bridged to Swift's String, so its methods appear as extensions on the built-in String type.

When you call one of the NSString methods, the object is magically bridged to Objective-C where it becomes a subclass of NSString.

Upvotes: 2

Related Questions