3. Swift Libraries
• swiftAST
• swiftLLVMParses
• swiftSIL
• swiftRuntime
• swiftCore
• swiftDarwin
• swiftFoundation
• etc.
4. Documentation
Sphinx documentation generator tool
Compiles .rst into HTML
• easy_install -U Sphinx
• make
In case make command fails...
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
source $HOME/.bash_profile
12. @_silgen_name
BridgeObjectiveC.swift
/// Convert `x` from its Objective-C representation to its Swift
/// representation.
@warn_unused_result
@_silgen_name("_forceBridgeFromObjectiveC_bridgeable")
public func _forceBridgeFromObjectiveC_bridgeable<T:_ObjectiveCBridgeable>(x: T._ObjectiveCType, _: T.Type) -> T {
var result: T?
T._forceBridgeFromObjectiveC(x, result: &result)
return result!
}
20. Swift Core
• Algorithm.swift
• Assert.swift
• Bool.swift
• BridgeObjectiveC.swift
• Builtin.swift
• CocoaArray.swift
• etc.
21. public func min<T : Comparable>(x: T, _ y: T) -> T
/// Returns the lesser of `x` and `y`.
///
/// If `x == y`, returns `x`.
@warn_unused_result
public func min<T : Comparable>(x: T, _ y: T) -> T {
// In case `x == y` we pick `x`.
// This preserves any pre-existing order in case `T` has identity,
// which is important for e.g. the stability of sorting algorithms.
// `(min(x, y), max(x, y))` should return `(x, y)` in case `x == y`.
return y < x ? y : x
}
22. public struct Bool
/// A value type whose instances are either `true` or `false`.
public struct Bool {
internal var _value: Builtin.Int1
/// Default-initialize Boolean value to `false`.
@_transparent
public init() {
let zero: Int8 = 0
self._value = Builtin.trunc_Int8_Int1(zero._value)
}
@_transparent
internal init(_ v: Builtin.Int1) { self._value = v }
}
23. public func _bridgeToObjectiveC<T>(x: T) ->
AnyObject?
/// Attempt to convert `x` to its Objective-C representation.
///
/// - If `T` is a class type, it is always bridged verbatim, the function
/// returns `x`;
///
/// - otherwise, `T` conforms to `_ObjectiveCBridgeable`:
/// + if `T._isBridgedToObjectiveC()` returns `false`, then the
/// result is empty;
/// + otherwise, returns the result of `x._bridgeToObjectiveC()`;
///
/// - otherwise, the result is empty.
@warn_unused_result
public func _bridgeToObjectiveC<T>(x: T) -> AnyObject? {
if _fastPath(_isClassOrObjCExistential(T.self)) {
return unsafeBitCast(x, AnyObject.self)
}
return _bridgeNonVerbatimToObjectiveC(x)
}
24. public prefix func ++ <T : _Incrementable> (inout i:
T) -> T
/// Replace `i` with its `successor()` and return the updated value of
/// `i`.
@_transparent
@available(*, deprecated, message="it will be removed in Swift 3")
public prefix func ++ <T : _Incrementable> (inout i: T) -> T {
i._successorInPlace()
return i
}
25. public func == <T: Equatable> (lhs: T?, rhs: T?) ->
Bool
@warn_unused_result
public func == <T: Equatable> (lhs: T?, rhs: T?) -> Bool {
switch (lhs, rhs) {
case let (l?, r?):
return l == r
case (nil, nil):
return true
default:
return false
}
}
26. public func map<T>(@noescape transform:
(Generator.Element) throws -> T) rethrows -> [T]
@warn_unused_result
public func map<T>(
@noescape transform: (Generator.Element) throws -> T
) rethrows -> [T] {
let initialCapacity = underestimateCount()
var result = ContiguousArray<T>()
result.reserveCapacity(initialCapacity)
var generator = generate()
// Add elements up to the initial capacity without checking for regrowth.
for _ in 0..<initialCapacity {
result.append(try transform(generator.next()!))
}
// Add remaining elements, if any.
while let element = generator.next() {
result.append(try transform(element))
}
return Array(result)
}
27. public func forEach(@noescape body:
(Generator.Element) throws -> Void) rethrows
public func forEach(
@noescape body: (Generator.Element) throws -> Void
) rethrows {
for element in self {
try body(element)
}
}