Last active
September 28, 2016 06:26
-
-
Save ken0nek/7e4e203b935b02236af5 to your computer and use it in GitHub Desktop.
【Swift】Int型の数字から[Int]型の配列を生成する。数字を桁ごとに分ける。 ref: http://qiita.com/ken0nek/items/825289a7f3ea1d840337
This file contains hidden or 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 num = 1234 | |
| let numList = "\(num)".characters.flatMap { Int("\($0)") } | |
| // let numList = String(num).characters.flatMap { Int(String($0)) } | |
| print(numList) | |
| // [1, 2, 3, 4] |
This file contains hidden or 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 num = 1234 | |
| let numList = "\(num)".characters.flatMap { Int("\($0)") } | |
| // let numList = String(num).characters.flatMap { Int(String($0)) } | |
| print(numList) | |
| // [1, 2, 3, 4] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment