Where is the Swift String API documentation?

Easiest: where can I find the API documentation for type String in Swift? Does something like this exist at all? It really should be for such a fundamental type. But even Google does not return anything useful.

You can get the Strings and Characters page, which, however, is a general overview of string processing. Or you can read the String page, which is terrible. Only a few pieces are mentioned there (some init, very few functions and some operators).

There is much more to String in the source code, but only with a marginal description and complex structure (since the actual APIs are divided into a dozen extensions).

To be clear: I'm looking for Swift String equivalence A reference to the NSString class .

+7
string swift
source share
2 answers

While in Swift, String not an instance or subtype of NSString , they actually have the same properties and methods. If you look at the NSString documentation, you will notice that each method described has a corresponding Swift language example.

Apple documents the basic behavior in Working with Cocoa Data Types :

Swift automatically connects between a string type and an NSString class. This means that wherever you use the NSString object, you can instead use the Swift String type and get the benefits of both types: interpolation of the String types and Swift-developed APIs and the wide functionality of the NSString classes. For this reason, you will almost never need to use the NSString class directly in your own code. In fact, when Swift imports the Objective-C API, it replaces all NSString types with String types. When your Objective-C code uses the Swift class, the importer replaces all NSString string types in the imported API.

To enable string binding, simply import Foundation. For example, you can call the capitalizedString method in the NSString class — in the Swift string, and Swift automatically translates the Swift String into an NSString object and calls the method. The method even returns a Swift String type because it was converted during import.

If you are looking for the Swift String declaration, it is not available through Apple's online documentation (although you can “Go to the declaration” in Xcode), but Nate Cook posted the documentation here: http://swiftdoc.org/type/String/

+5
source share

Apple Swift Library white papers for row

Although they may be more readable on SwiftDoc

And this post by Apple also deserves attention.

+3
source share

All Articles