Skip to content

Instantly share code, notes, and snippets.

@ktanaka117
Created February 20, 2016 12:48
Show Gist options
  • Save ktanaka117/901caf50183d061dec60 to your computer and use it in GitHub Desktop.
Save ktanaka117/901caf50183d061dec60 to your computer and use it in GitHub Desktop.
import UIKit
class ViewController: UIViewControlle {
@IBOutlet weak var textField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// !!! なんか長い !!!
NSNotificationCenter.defaultCenter().addObserver(self, selector: "textDidChange:", name: UITextFieldTextDidChangeNotification, object: textField)
}
// !!! 処理が遠い&ジャンプできない !!!
func textDidChange(notification: NSNotification) {
print((notification.object as? UITextField)?.text)
}
// !!! deinit時にremoveし忘れる !!!
deinit {
NSNotificationCenter.defaultCenter().removeObserver(self)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment