2. 諏訪 悠紀
• underscore Inc.
• Develop, Design, and More...
• iOS, Android, and More...
http://dev.classmethod.jp/author/suwa-yuki/
Blog
http://underscore-app.tumblr.com/
Apps
18. タプルを分解して代入
// タプル
let fooBar = ("foo", "bar")
let (a, b) = fooBar
a // foo
b // bar
!
// ワイルドカード
let (foo, _) = fooBar
foo // foo
!
19. for in
// タプルの配列を回す
let tupleList = [(0, 1), (1, 2), (1, 3)]
var tupleListStr: String = ""
for (_, b) in tupleList {
tupleListStr += "(b),"
}
tupleListStr // 1,2,3,
!
// Indexと値を取る
for (index, v) in enumerate(list) {
str += "(index):(v),"
}
str // 0:foo,1:bar,2:baz,
20. switch内でのwhere
let values = (30, 41)
var maxValue: Int
!
switch values {
case let (a, b) where a > b:
maxValue = a
case let (a, b) where a < b:
maxValue = b
case let (a, b):
maxValue = a
}
!
maxValue // 41