struct UnsafePointer<Pointee> : Strideable, Hashable {
var pointee: Pointee { get } subscript(i: Int) -> Pointee { get } }
class Item {
// 戻り値を使わないと警告される @warn_unused_result func makeFilter() -> Filter {…}
// 戻り値を使わなくても警告されない func apply(filter: Filter) -> Item {…} }
class Item {
// 戻り値を使わないと警告される func makeFilter() -> Filter {…}
// 戻り値を使わなくても警告されない @discardableResult func apply(filter: Filter) -> Item {…} }
struct Value {
init!(source: Int) { … } func doSomething() { … } }
let value = Value(source: 10)
value?.doSomething() Value?
Value!
enum Item { case binary(NSData) }
let data1: NSMutableData = … let data2: NSData = …
let item = Item.binary(data1)
data1.appendData(data2)
enum Item { case binary(Data) }
var data1: Data = … let data2: Data = …
let item = Item.binary(data1)
data1.appendData(data2)
// 最初のインデックス var startIndex: Index { get }
// 最後の次のインデックス var endIndex: Index { get }
// 指定したインデックスに該当する要素 subscript (position: Index) -> _Element { get }
// 最初のインデックス var startIndex: Index { get }
// 最後の次のインデックス var endIndex: Index { get }
// 指定したインデックスに該当する要素 subscript (position: Index) -> _Element { get }
// あるインデックスの次のインデックスを取得 func index(after i: Index) -> Index
// 前方移動性をもつ索引型 protocol ForwardIndexType: Equatable // 前後方移動性をもつ索引型 protocol BidirectionalIndexType: ForwardIndexType // どこへも自由に即時移動できる索引型 protocol RandomAccessIndexType: BidirectionalIndexType // コレクションは集積性と、使用する索引を規定 protocol CollectionType { associatedtype Index : ForwardIndexType
// 前方移動性をもつコレクション protocol Collection: Indexable // 前後方移動性をもつコレクション protocol BidirectionalCollection: BidirectionalIndexable // 範囲内を自由に即時移動できるコレクション protocol RandomAccessCollection: RandomAccessIndexable // インデックスに求められるのは比較性のみ protocol Collection { associatedtype Index : Comparable
// このコレクションは前後へ移動可能 struct MyCollection : BidirectionalCollection {
// 索引として文字列を使う typealias Index = String
}
// Int を索引にもつデータ表現は実装の手間が増える struct MyArray<Element> : RandomAccessCollection {
typealias Index = Int
}
// String を索引にもつデータ表現は簡略化される struct Namelist : Collection {
typealias Index = String
!, &&, ||
func && (lhs: Bool, rhs: () -> Bool) -> Bool func || (lhs: Bool, rhs: () -> Bool) -> Bool
func ! (a: Bool) -> Bool
// 定義では `` が必要 enum DrawingStyle { case `default` case `repeat` case fit }
// 使用時は `` が不要 let style = DrawingStyle.default
// 定義では `` が必要 class Object {
var `default`: Int func `repeat`(_ times: Int) -> String { … } }
// 使用時は `` が不要 let object = Object() let value = object.default
// 定義では `` が必要 enum Evaluate { case `self` case `dynamicType` }
// 使用時も `` が必要 let eval = Evaluate.`self`
// 既定値が指定された関数があったとき func something(a:Int = 0, b:Int = 1, c:Int = 2) { }
// 異なる順番で引数を渡せなくなった something(b: 10, a: 20)
func function() -> (@autoclosure () -> Int) -> Int {
return { (f: @autoclosure () -> Int) in f() } }
// 関数で得た、関数を取る関数に、値をそのまま渡せる let f = function() let result = f(100)
func function() -> (result: inout Int) -> Void {
return { (result: inout Int) -> Void in
result = 700 } }
func something(value: inout Int) {
let noescaped: @noescape () -> Void = { value = 10 }
let escaped: () -> Void = { [value] in print(value) } }
typealias NamedValues<T> = Dictionary<String, T> typealias Vector<T> = (T, T) typealias Filter<T,R> = (T) -> R
switch (value1, value2) {
case let (value?, nil), let (nil, value?): return value
case let (value1?, value2?): return value1 + value2
case (nil, nil): return 0 }
Top Related