Last active
August 29, 2015 14:02
-
-
Save preble/4ec26bd33b32362e64e9 to your computer and use it in GitHub Desktop.
Random app in Swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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