UISwitchがonの時は”1” offの時は"0"にしたい
下記のコードはビルドは失敗してしまいます。
UISwitchがonの時、変数firstの値は1、offの時は0にしたいのですが、方法がわかいりません。
ご教授願います。
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var first: UISwitch!
override func viewDidLoad() {
super.viewDidLoad()
// SwitchのOn/Off切り替わりの際に、呼ばれるイベントを設定する.
first.addTarget(self, action: "onClickMySwicth:", forControlEvents: UIControlEvents.ValueChanged)
}
internal func onClickMySwicth(sender: UISwitch){
if sender.on { print("1")}
else { print("0")}
}
}
ビルドの途中で、下記のようなエラー表示が出ます。
ご教授お願いします。
2016-02-05 21:11:37.598 139[607:8643] * Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<_39.ViewController 0x7fb1d1c2ef60> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key ferst.'
* First throw call stack:
(
0 CoreFoundation 0x000000010436de65 exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001060addeb objc_exception_throw + 48
2 CoreFoundation 0x000000010436daa9 -[NSException raise] + 9
3 Foundation 0x00000001047369bb -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288
4 UIKit 0x0000000104d19320 -[UIViewController setValue:forKey:] + 88
5 UIKit 0x0000000104f47f41 -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x00000001042ae4a0 -[NSArray makeObjectsPerformSelector:] + 224
7 UIKit 0x0000000104f46924 -[UINib instantiateWithOwner:options:] + 1864
8 UIKit 0x0000000104d1feea -[UIViewController _loadViewFromNibNamed:bundle:] + 381
9 UIKit 0x0000000104d20816 -[UIViewController loadView] + 178
10 UIKit 0x0000000104d20b74 -[UIViewController loadViewIfRequired] + 138
11 UIKit 0x0000000104d212e7 -[UIViewController view] + 27
12 UIKit 0x0000000104bf7ab0 -[UIWindow addRootViewControllerViewIfPossible] + 61
13 UIKit 0x0000000104bf8199 -[UIWindow _setHidden:forced:] + 282
14 UIKit 0x0000000104c09c2e -[UIWindow makeKeyAndVisible] + 42
15 UIKit 0x0000000104b82663 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4131
16 UIKit 0x0000000104b88cc6 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1760
17 UIKit 0x0000000104b85e7b -[UIApplication workspaceDidEndTransaction:] + 188
18 FrontBoardServices 0x0000000107f42754 -[FBSSerialQueue _performNext] + 192
19 FrontBoardServices 0x0000000107f42ac2 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
20 CoreFoundation 0x0000000104299a31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
21 CoreFoundation 0x000000010428f95c __CFRunLoopDoSources0 + 556
22 CoreFoundation 0x000000010428ee13 __CFRunLoopRun + 867
23 CoreFoundation 0x000000010428e828 CFRunLoopRunSpecific + 488
24 UIKit 0x0000000104b857cd -[UIApplication _run] + 402
25 UIKit 0x0000000104b8a610 UIApplicationMain + 171
26 139 0x00000001041904cd main + 109
27 libdyld.dylib 0x0000000106bb692d start + 1
28 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)