Extensions
The following extensions are available globally.
-
An arbitrary Unicode string value.Unicode-Correct ===============Swift strings are designed to be Unicode-correct. In particular, the APIs make it easy to write code that works correctly, and does not surprise end-users, regardless of where you venture in the Unicode character space. For example,
- The
==
operator checks for Unicode canonical equivalence, so two different representations of the same string will always compare equal. - String elements are
Characters
(Unicode extended grapheme clusters), a unit of text that is meaningful to most humans.
Dictionary<String, T>
in a running program depends on a given string comparison having a single, stable result. Therefore, Swift always uses the default, un-tailored Unicode algorithms for basic string operations.ImportingFoundation
endows swift strings with the full power of theNSString
API, which allows you to choose more complex locale-sensitive operations explicitly.Value Semantics ===============Each string variable,let
binding, or stored property has an independent value, so mutations to the string are not observable through its copies::var a = "foo" var b = a b[b.endIndex.predecessor()] = "x" println("a=(a), b=(b)") // a=foo, b=fox
Strings use Copy-on-Write so that their data is only copied lazily, upon mutation, when more than one string instance is using the same buffer. Therefore, the first in any sequence of mutating operations may costO(N)
time and space, whereN
is the length of the string's (unspecified) underlying representation,.Growth and Capacity ===================When a string's contiguous storage fills up, new storage must be allocated and characters must be moved to the new storage.String
uses an exponential growth strategy that makesappend
a constant time operation when amortized over many invocations.Objective-C Bridge ==================String
is bridged to Objective-C asNSString
, and aString
that originated in Objective-C may store its characters in anNSString
. Since any arbitrary subclass ofNSSString
can become aString
, there are no guarantees about representation or efficiency in this case. SinceNSString
is immutable, it is just as though the storage was shared by some copy: the first in any sequence of mutating operations causes elements to be copied into unique, contiguous storage which may costO(N)
time and space, whereN
is the length of the string representation (or more, if the underlyingNSString
is has unusual performance characteristics).Declaration
Swift
struct String
- The
-
An NSURLRequest object represents a URL load request in a manner independent of protocol and URL scheme. NSURLRequest encapsulates two basic data elements about a URL load request:
- The URL to load.
- The policy to use when consulting the URL content cache made available by the implementation.
- Protocol implementors should direct their attention to the NSURLRequestExtensibility category on NSURLRequest for more information on how to provide extensions on NSURLRequest to support protocol-specific request information.
- Clients of this API who wish to create NSURLRequest objects to load URL content should consult the protocol-specific NSURLRequest categories that are available. The NSHTTPURLRequest category on NSURLRequest is an example.
Objects of this class are used to create NSURLConnection instances, which can are used to perform the load of a URL, or as input to the NSURLConnection class method which performs synchronous loads.
Declaration
Swift
@interface NSURLRequest : NSObject <NSSecureCoding, NSCopying, NSMutableCopying> { NSURLRequestInternal *_internal; } @end
-
An NSURLRequest object represents a URL load request in a manner independent of protocol and URL scheme. NSURLRequest encapsulates two basic data elements about a URL load request:
- The URL to load.
- The policy to use when consulting the URL content cache made available by the implementation.
- Protocol implementors should direct their attention to the NSURLRequestExtensibility category on NSURLRequest for more information on how to provide extensions on NSURLRequest to support protocol-specific request information.
- Clients of this API who wish to create NSURLRequest objects to load URL content should consult the protocol-specific NSURLRequest categories that are available. The NSHTTPURLRequest category on NSURLRequest is an example.
Objects of this class are used to create NSURLConnection instances, which can are used to perform the load of a URL, or as input to the NSURLConnection class method which performs synchronous loads.
Declaration
Swift
@interface NSURLRequest : NSObject <NSSecureCoding, NSCopying, NSMutableCopying> { NSURLRequestInternal *_internal; } @end
-
Responsible for sending a request and receiving the response and associated data from the server, as well as managing its underlying
NSURLSessionTask
.Declaration
Swift
public class Request
-
Responsible for creating and managing
Request
objects, as well as their underlyingNSURLSession
.Declaration
Swift
public class Manager
-
Responsible for sending a request and receiving the response and associated data from the server, as well as managing its underlying
NSURLSessionTask
.Declaration
Swift
public class Request
-
Responsible for creating and managing
Request
objects, as well as their underlyingNSURLSession
.Declaration
Swift
public class Manager
-
Responsible for sending a request and receiving the response and associated data from the server, as well as managing its underlying
NSURLSessionTask
.Declaration
Swift
public class Request
-
Responsible for sending a request and receiving the response and associated data from the server, as well as managing its underlying
NSURLSessionTask
.Declaration
Swift
public class Request
-
Responsible for sending a request and receiving the response and associated data from the server, as well as managing its underlying
NSURLSessionTask
.Declaration
Swift
public class Request
-
Responsible for sending a request and receiving the response and associated data from the server, as well as managing its underlying
NSURLSessionTask
.Declaration
Swift
public class Request
-
Responsible for sending a request and receiving the response and associated data from the server, as well as managing its underlying
NSURLSessionTask
.Declaration
Swift
public class Request
-
Responsible for sending a request and receiving the response and associated data from the server, as well as managing its underlying
NSURLSessionTask
.Declaration
Swift
public class Request