Skip to content

Instantly share code, notes, and snippets.

@hekt
Created November 3, 2014 10:10
Show Gist options
  • Save hekt/a688c822693ec2682e7f to your computer and use it in GitHub Desktop.
Save hekt/a688c822693ec2682e7f to your computer and use it in GitHub Desktop.
LetterCountChallenge アプリケーションの Swift 版 (『MAC OS X COCOA プログラミング』第5章)
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var window: NSWindow!
@IBOutlet weak var textField: NSTextField!
@IBOutlet weak var textLabel: NSTextField!
@IBAction func countChars(sender: AnyObject) {
let str = textField.stringValue
let count = countElements(str)
textLabel.stringValue = "'\(str)' has \(count) characters."
}
func applicationDidFinishLaunching(aNotification: NSNotification) {
// Insert code here to initialize your application
}
func applicationWillTerminate(aNotification: NSNotification) {
// Insert code here to tear down your application
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment