Skip to content

Instantly share code, notes, and snippets.

@preble
Last active August 29, 2015 14:02
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save preble/4ec26bd33b32362e64e9 to your computer and use it in GitHub Desktop.
Save preble/4ec26bd33b32362e64e9 to your computer and use it in GitHub Desktop.
Random app in Swift
import Cocoa
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet var window: NSWindow
@IBOutlet var label: NSTextField
func applicationDidFinishLaunching(aNotification: NSNotification?) {
// Insert code here to initialize your application
}
func applicationWillTerminate(aNotification: NSNotification?) {
// Insert code here to tear down your application
}
@IBAction func seed(sender: AnyObject) {
srandom(CUnsignedInt(time(nil)));
label.stringValue = "Seed"
}
@IBAction func generate(sender: AnyObject) {
var generated = (random() % 100) + 1
label.stringValue = "Generated \(generated)"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment