Last active
September 28, 2016 06:15
-
-
Save ken0nek/8db275f51e61592e3ec5 to your computer and use it in GitHub Desktop.
【Swift】enumerateを使ったときの値の受け取り方 ref: http://qiita.com/ken0nek/items/5c9c3f5138fbbaf5e82c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[1, 2, 3, 4] -> ["0:1", "1:2", "2:3", "3:4"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let array = [1, 2, 3, 4] | |
let pairList = array.enumerated().map { (tuple: (i: Int, ele: Int)) -> String in | |
return "\(tuple.i):\(tuple.ele)" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let array = [1, 2, 3, 4] | |
let pairList = array.enumerated().map { tuple in | |
return "\(tuple.0):\(tuple.1)" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let array = [1, 2, 3, 4] | |
let pairList = array.enumerated().map { tuple in | |
return "\(tuple.offset):\(tuple.element)" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let array = [1, 2, 3, 4] | |
let pairList = array.enumerated().map { (i: Int, ele: Int) in | |
return "\(i):\(ele)" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let array = [1, 2, 3, 4] | |
let pairList = array.enumerated().map { (i, ele) in | |
return "\(i):\(ele)" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let array = [1, 2, 3, 4] | |
let pairList = array.enumerated().map { "\($0.0):\($0.1)" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (i, ele) in [1, 2, 3, 4].enumerated() { | |
print(i, ele) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for tuple in [1, 2, 3, 4].enumerated() { | |
print(tuple.offset, tuple.element) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment