class Item {
// 戻り値を使わないと警告される @warn_unused_result func makeFilter() -> Filter {…}
// 戻り値を使わなくても警告されない func apply(filter: Filter) -> Item {…} }
class Item {
// 戻り値を使わないと警告される func makeFilter() -> Filter {…}
// 戻り値を使わなくても警告されない @discardableResult func apply(filter: Filter) -> Item {…} }
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)
Advance to the next element and return it, or `nil` if no next element exists.Once `nil` has been returned, all subsequent calls return `nil`.
protocol IteratorProtocol {
associatedtype Element mutating func next() -> Element?
func remove<T:BooleanType>(recursively flag: T) {
… }
func isKindOf<R:BooleanType>(type: AnyType) -> R {
… }
!, &&, ||
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`
class Base : Equatable { func isEqual(to rhs: Base) -> Bool {…} } class Sub : Base { override func isEqual(to rhs: Base) -> Bool {…} } func == (lhs: Base, rhs: Base) -> Bool { return lhs.isEqual(to: rhs) }
class Base : Equatable {
class func == (lhs: Base, rhs: Base) -> Bool {…} }
class Sub : Base {
override class func == (lhs: Base, rhs: Base) -> Bool {…} }
func makeIncrementer(inout value: Int) -> () -> Void { return { value += 1; print("Inside:", value) } }
var value = 1 let incrementer = makeIncrementer(&value)
print("Outside:", value) // Outside: 1 incrementer() // Inside: 2 print("Outside:", value) // Outside: 1 incrementer() // Inside: 3 print("Outside:", value) // Outside: 1
func something(value: inout Int) {
let noescaped: @noescape () -> Void = { value = 10 }
let escaped: () -> Void = { [value] in print(value) } }
func total(price: Int, count: Int) -> Int {
}
// 引数リストを丸ごとタプルで扱える let item: (Int, count: Int) = (100, 5)
total(item)
func total(price: Int, count: Int) -> Int {
}
// 原則、引数リストを1つのタプルで表現できない let item: (Int, count: Int) = (100, 5)
total(item)
func apply<T, R>(value: T, f: (T) -> R) -> R {
return f(value) }
let item: (Int, count: Int) = (100, 5) func total(price: Int, count: Int) -> Int { … }
apply(value: item, f: total)
switch (value1, value2) {
case let (value?, nil), let (nil, value?): return value
case let (value1?, value2?): return value1 + value2
case (nil, nil): return 0 }
switch device {
case let .iPhone(_, osVersion, network, _) where osVersion > 8.0, let .iPad(_, osVersion, network, _, true) where network == .cellular,
doSomething(device, osVersion, network) case .iPodTouch: doSomething(device) default: doSomething() }