sourcekitten Docs (93% documented)

sourcekitten Reference Extensions Reference

Extensions

The following extensions are available globally.

  • Conceptually_, Array is an efficient, tail-growable random-access collection of arbitrary elements.Common Properties of Array Types ================================The information in this section applies to all three of Swift’s array types, Array<T>, ContiguousArray<T>, and Slice<T>. When you read the word array here in a normal typeface, it applies to all three of them.Value Semantics —————Each array variable, let binding, or stored property has an independent value that includes the values of all of its elements. Therefore, mutations to the array are not observable through its copies::

    var a = [1, 2, 3] var b = a b[0] = 4 println(a=\(a), b=\(b)) // a=[1, 2, 3], b=[4, 2, 3]
    (Of course, if the array stores class references, the objects are shared; only the values of the references are independent)Arrays use Copy-on-Write so that their storage and elements are only copied lazily, upon mutation, when more than one array instance is using the same buffer. Therefore, the first in any sequence of mutating operations may cost O(N) time and space, where N is the length of the array.Growth and Capacity ——————-When an array’s contiguous storage fills up, new storage must be allocated and elements must be moved to the new storage. Array, ContiguousArray, and Slice share an exponential growth strategy that makes append a constant time operation when amortized over many invocations. In addition to a count property, these array types have a capacity that reflects their potential to store elements without reallocation, and when you know how many elements you’ll store, you can call reserveCapacity to pre-emptively reallocate and prevent intermediate reallocations… _Conceptually:Objective-C Bridge ==================The main distinction between Array and the other array types is that it interoperates seamlessly and efficiently with Objective-C.Array<T> is considered bridged to Objective-C iff T is bridged to Objective-C.When T is a class or @objc protocol type, Array may store its elements in an NSArray. Since any arbitrary subclass of NSArray can become an Array, there are no guarantees about representation or efficiency in this case (see also ContiguousArray). Since NSArray 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 cost O(N) time and space, where N is the length of the array (or more, if the underlying NSArray is has unusual performance characteristics).Bridging to Objective-C ———————–Any bridged Array can be implicitly converted to an NSArray. When T is a class or @objc protocol, bridging takes O(1) time and O(1) space. Other Array\ s must be bridged element-by-element, allocating a new object for each element, at a cost of at least O(count) time and space.Bridging from Objective-C ————————-An NSArray can be implicitly or explicitly converted to any bridged Array<T>. This conversion calls copyWithZone on the NSArray, to ensure it won’t be modified, and stores the result in the Array. Type-checking, to ensure the NSArray\ ’s elements match or can be bridged to T, is deferred until the first element access.

    Declaration

    Swift

    struct Array<T> : MutableCollectionType, Sliceable
  • A hash-based mapping from Key to Value instances. Also a collection of key-value pairs with no defined ordering.

    Declaration

    Swift

    struct Dictionary<Key : Hashable, Value> : CollectionType, DictionaryLiteralConvertible
  • 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.
    Locale-Insensitive ==================The fundamental operations on Swift strings are not sensitive to locale settings. That’s because, for example, the validity of a 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.Importing Foundation endows swift strings with the full power of the NSString 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 cost O(N) time and space, where N 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 makes append a constant time operation when amortized over many invocations.Objective-C Bridge ==================String is bridged to Objective-C as NSString, and a String that originated in Objective-C may store its characters in an NSString. Since any arbitrary subclass of NSSString can become a String, there are no guarantees about representation or efficiency in this case. Since NSString 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 cost O(N) time and space, where N is the length of the string representation (or more, if the underlying NSString is has unusual performance characteristics).

    Declaration

    Swift

    struct String
  • ************** Immutable Data ***************

    Declaration

    Swift

    @interface NSData : NSObject <NSCopying, NSMutableCopying, NSSecureCoding>
    @end
  • A 64-bit unsigned integer value type.

    Declaration

    Swift

    struct UInt64 : UnsignedIntegerType
  • A 64-bit signed integer value type.

    Declaration

    Swift

    struct Int64 : SignedIntegerType
  • A value type whose instances are either true or false.

    Declaration

    Swift

    struct Bool