初めてのターミナルプログラム

Af64bc38c0ffcfcabdf430759ee491ce?s=47 Elvis Shi
March 09, 2018

 初めてのターミナルプログラム

Af64bc38c0ffcfcabdf430759ee491ce?s=128

Elvis Shi

March 09, 2018
Tweet

Transcript

  1. ॳΊͯͷ
 λʔϛφϧϓϩάϥϜ forUSZ4XJGU5PLZP"GUFSUBMLT

  2. var employedBy = "YUMEMI Inc." var job = "iOS Developer"

    var favoriteLanguage = "Swift" var twitter = "@lovee" var qiita = "lovee" var github = "el-hoshino" var additionalInfo = """ ΏΔΏΔΩϟϯϓ΋͘΋͘ձɺࢀՃऀืूத """ class Me: Developable, Talkable { }
  3. ༷ʑͳλʔϛφϧϓϩάϥϜ ▸ QJOH ▸ CSFX ▸ HJU ▸ LVSJ ▸

    IBOBLP ▸ FSVUBTP 1kuri: https://github.com/bannzai/Kuri 2hanako: https://github.com/el-hoshino/hanako 3erutaso: https://github.com/sgymtic/sl
  4. ࣗ෼΋࡞Ζ͏

  5. ·ͣ͸ੈքʹ
 ѫࡰ͠Α͏

  6. 9DPEF
 ʷ
 4XJGU

  7. None
  8. import Foundation print("Hello, World!")

  9. import Foundation print("Hello, World!")

  10. import Foundation print("Hello, World!")

  11. $ cd {path/to/project/dir} $ xcodebuild $ cp build/Release/{app_name} /usr/local/bin $

    {app_name} hello, world! 今回は簡単なプログラムなので
 Xcode 使わずに `swiftc` で
 ビルドしてもいいけど
 まあいいや
  12. Ͷɺ؆୯Ͱ ͠ΐʁ

  13. $ cd {path/to/project/dir} $ xcodebuild $ cp build/Release/{app_name} /usr/local/bin $

    {app_name} hello, world! コマンド引数って
 どうやって取るんだろ
  14. import Foundation CommandLine.arguments: [String]

  15. None
  16. import Foundation let candidates = Array(CommandLine.arguments.dropFirst()) var outputs: [String] =

    [] output: while let random = candidates.random { print(random) outputs.append(random) outputs.keepLast(candidates.count) if outputs == candidates { print(outputs.joined(separator: " ") .appending("!")) break output } }
  17. import Foundation extension Array { var random: Element? { guard

    self.isEmpty == false else { return nil } let randomIndex = arc4random_uniform(UInt32(self.count)) return self[Int(randomIndex)] } mutating func keepLast(_ n: Int = 1) { guard self.count > n else { return } let removingElementsCount = self.count - n self.removeFirst(removingElementsCount) } }
  18. %&.0