Reputation:
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
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