A simple as that: where can I find the API documentation for the String type in Swift? Does something like that exist at all? It really should for such a fundamental type. But not even Google returns anything useful.
You can get the Strings and Characters page, which is however a general overview about String handling. Or you can read the String page which is terrible. There's only a handful stuff mentioned (some init, very few functions and some operators).
Looking in the source code for String there's a lot more, but only with marginal description and complex structure (as the actual APIs are split over a dozen extensions).
To make it clear: I'm looking for the Swift String equivalence of the NSString Class Reference.
While in Swift, String
is not an instance or subtype of NSString
, they effectively have the same properties and methods. If you look at the NSString
documentation, you'll notice each method documented has an appropriate Swift language example.
Apple documents the underlying behavior in "Working with Cocoa Data Types":
Swift automatically bridges between the String type and the NSString class. This means that anywhere you use an NSString object, you can use a Swift String type instead and gain the benefits of both types—the String type’s interpolation and Swift-designed APIs and the NSString class’s broad functionality. For this reason, you should almost never need to use the NSString class directly in your own code. In fact, when Swift imports Objective-C APIs, it replaces all of the NSString types with String types. When your Objective-C code uses a Swift class, the importer replaces all of the String types with NSString in imported API.
To enable string bridging, just import Foundation. For example, you can call capitalizedString—a method on the NSString class—on a Swift string, and Swift automatically bridges the Swift String to an NSString object and calls the method. The method even returns a Swift String type, because it was converted during import.
If you're looking for the Swift declaration of String
, it doesn't appear available through Apple's online documentation (though you can "Jump to Declaration" in Xcode), but Nate Cook has published the documentation here:
http://swiftdoc.org/type/String/
Official Apple Swift Library Docs for String
Although they may be more readable at SwiftDoc
And this Apple blog post is also worth reading.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With