Thursday, May 4, 2017

Swift: Random Message Example

Command:

$ cat /Users/username/Desktop/macOS\ Swift\ Test/macOS\ Swift\ Test/main.swift


Result:

import Foundation
import Darwin

let goodmorning: Array<String> = ["おはよう!","おはようございます。","やあ!","ねむたそうだね","おっはー!","グッドモーニング!","モーニング!","今日もよろしく!"]

let randomIndex = Int(arc4random_uniform(UInt32(goodmorning.count)))

print("\(goodmorning[randomIndex])")


Command:

$ /Users/username/Library/Developer/Xcode/DerivedData/macOS_Swift_Test-arwavijyybnxpmctpfzeonufbnvy/Build/Products/Debug/macOS\ Swift\ Test ;

Result:

モーニング!