iOS オールスターズ2でお話しした資料です! Swift らしさってなんだろう、そんなところを API デザインガイドラインと Swift 標準ライブラリの表現に着目して 7 つほど紹介してみました。あくまでも "指針" なので『そういう風に考えていくのね』みたいに捉えて、そこからは "自分らしい" 言葉を紡いでいってくれたらいいのかなって思います。
iOS オールスターズ2でお話しした資料です! Swift らしさってなんだろう、そんなところを API デザインガイドラインと Swift 標準ライブラリの表現に着目して 7 つほど紹介してみました。あくまでも "指針" なので『そういう風に考えていくのね』みたいに捉えて、そこからは "自分らしい" 言葉を紡いでいってくれたらいいのかなって思います。
The document discusses Swift features related to variables, functions, and protocols. It provides examples of using var and inout keywords to pass variables by reference into functions. It also demonstrates defining generic functions that accept parameters and return functions.
The document discusses Swift features related to variables, functions, and protocols. It provides examples of using var and inout keywords to pass variables by reference into functions. It also demonstrates defining generic functions that accept parameters and return functions.
みんなで Swift 復習会での談笑用スライド – in 札幌 1st′ #minna_de_swiftTomohiro Kumagai
This document introduces some basic variable declarations in Swift including let constants for pi and attempts, a var variable for amount, and defines a maxCapacity constant as an Int with an initial value of 100 that is later reassigned to 20. It also declares a price constant as a Double.
2019/12/25 に開催した「みんなで Swift 復習会 GO! in 札幌」で使用した資料です。主にオープニング用の資料で、本編で使ったスライドは僅かで現場にいないと役に立たないかもしれませんが、何かの参考用に公開します。
実際の現場で使った本編資料は2ページですけれど、話が脱線する中で詳細に触れた項目が記載されていたページも数ページですけれど公開しておきました。
2018/11/09 の Swift 愛好会の LT で『Swift の let した変数に値を再代入してみよう』という問題提起をするのに使ったオープニング的なスライドです。
このスライドに「解答」は含まれていないので、この話題をきっかけにあれこれ試行錯誤して、さらにはそこから『どうして2回、代入することができたのか』みたいな理由を考える糸口にしてもらえたら嬉しいです。
This code snippet shows two switch statements in Swift. The first switch statement matches on a variable v and prints different outputs depending on which pattern matches. The second switch statement matches on a device variable and can match multiple patterns on one case or use a where clause to check for a suffix, printing outputs accordingly.
The document discusses control flow statements in Swift including if/else statements to check conditions, switch statements to check multiple options, and looping statements like for-in, while and repeat-while. It also provides examples of if let to safely unwrap optionals and the nil coalescing operator ?? to handle nil values.
25. // 型に ! を添えて定義する(従前どおり)
let implicitly: Int! = 100
// 型明記せずに受けると、その変数は普通の Optional 型
let optional = implicitly
Int?
26. // Int! を返す関数があったとき …
func something() -> Int! {…}
// 暗黙アンラップとして即使用する方法(受け手は戻り値の型)
let result = something().advanced(by: 1)
// 速やかに解消する方法(受け手は Int 型)
let result = something()!
// nil の可能性を残して先へ(受け手は Int? 型)
let result = something()
34. let fibonacci = AnySequence {()-> AnyIterator<Int> in
var data = (0, 1)
return AnyIterator {
defer {
data = (data.1, data.0 + data.1)
}
return data.1
}
}
35. var previous2 = 0
let fibonacci = sequence(first: 1) { previous1 in
defer {
previous2 = previous1
}
return previous1 + previous2
}
36. let fibonacci = sequence(state: (0, 1)) {
(state: inout (Int, Int)) -> Int? in
defer {
state = (state.1, state.0 + state.1)
}
return state.1
}
37.
38. // Swift 3 での探し方
let value: Int? = fibonacci.first { $0 > 100 }
// Swift 2 での探し方
var value: Int? {
for v in fibonacci where v > 100 {
return v
}
return nil
}
39.
40. // 次のインデックスを取得
let next = index.successor()
// 前のインデックスを取得
let previous = index.predeessor()
41. // 扱うインデックスの範囲
let indices = items.indices
// あるインデックスの次を取得
let next = items.index(after: index)
// あるインデックスの前を取得
let previous = items.index(before: index)