Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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

Elvis Shi
March 09, 2018

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

Elvis Shi

March 09, 2018
Tweet

More Decks by Elvis Shi

Other Decks in Programming

Transcript

  1. 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 { }
  2. ༷ʑͳλʔϛφϧϓϩάϥϜ ▸ 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
  3. $ cd {path/to/project/dir} $ xcodebuild $ cp build/Release/{app_name} /usr/local/bin $

    {app_name} hello, world! 今回は簡単なプログラムなので
 Xcode 使わずに `swiftc` で
 ビルドしてもいいけど
 まあいいや
  4. $ cd {path/to/project/dir} $ xcodebuild $ cp build/Release/{app_name} /usr/local/bin $

    {app_name} hello, world! コマンド引数って
 どうやって取るんだろ
  5. 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 } }
  6. 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) } }