REPLモードでswiftを動かしてみました
概要
REPLモードとシェルモードでギーク開発にあるswiftスクリプトを実行してみました。
GUI付きのシェルスクリプト(コマンド)とかに使えそうですね。swiftにはこのような使い方もあるんですね。
$ cat today.swift #!/usr/bin/swift import Foundation let today = NSDate() println("現在時刻は \(today) です")
実行結果
$ ./today.swift 現在時刻は 2015-12-06 23:05:30 +0000 です
GUI(ダイアログ)を開き、その結果に基づき、ブラウザを起動する。
ちょっとしたアプリ(ツール)が作成できそうです。
$ cat openurl.command #!/usr/bin/swift import Foundation import AppKit let alert = NSAlert() alert.alertStyle = NSAlertStyle.InformationalAlertStyle alert.messageText = "Geekroid(仮)のページをブラウザで開きます。よろしいですか?" alert.addButtonWithTitle("OK") alert.addButtonWithTitle("Cancel") let res:Int = alert.runModal() if (res == NSAlertFirstButtonReturn) { NSWorkspace.sharedWorkspace().openURL(NSURL(string: "http://mynavi-agent.jp/it/geekroid/")!) }
$ ./openurl.command
関連情報
- REPLモードとシェルモードでギーク開発