import UIKit
class SignUpViewController: UIViewController
{
@IBOutlet weak var usernametext: UITextField!
@IBOutlet weak var emailtext: UITextField!
@IBOutlet weak var passwordtext: UITextField!
@IBOutlet weak var retypepasswordtext: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.h
}
@IBAction func Signupbutton(sender: AnyObject) {
let username = usernametext.text ;
let useremail = emailtext.text ;
let password = passwordtext.text ;
let retypepassword = retypepasswordtext.text ;
//alert message with confirmation
func displayMyAlertMessage(UserMessage :String)
{
var myalert=UIAlertController(title:"Alert", message:UserMessage,preferredStyle: UIAlertControllerStyle.Alert)
let okAction = UIAlertAction(title: "ok", style:UIAlertActionStyle.Default , handler: nil)
myalert.addAction(okAction)
self.presentViewController(myalert, animated: true, completion: nil)
}
//check empty fields
if(username.isEmpty || useremail.isEmpty || password.isEmpty || retypepassword.isEmpty)
{
//display alert message
displayMyAlertMessage("all fields are reqiured");
return;
}
//password match
if(password != retypepassword)
{
//display alert message
displayMyAlertMessage("passwords do not match");
return;
}
//store data
NSUserDefaults.standardUserDefaults().setObject(username, forKey: "username")
NSUserDefaults.standardUserDefaults().setObject(useremail, forKey: "email")
NSUserDefaults.standardUserDefaults().setObject(password, forKey: "password")
NSUserDefaults.standardUserDefaults().setObject(retypepassword, forKey: "retypepassword")
//alert msg
}
}
error shown:-
2015-06-08 13:24:18.163 login excersice[3506:334174] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<login_excersice.SignUpViewController 0x7be6e4e0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key email.'
*** First throw call stack:
(
0 CoreFoundation 0x00293946 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x01c6fa97 objc_exception_throw + 44
2 CoreFoundation 0x00293561 -[NSException raise] + 17
3 Foundation 0x0071a10e -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 282
4 Foundation 0x00676138 _NSSetUsingKeyValueSetter + 115
5 Foundation 0x006760bd -[NSObject(NSKeyValueCoding) setValue:forKey:] + 267
6 Foundation 0x006ab9a6 -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 386
7 UIKit 0x00ddc649 -[UIRuntimeOutletConnection connect] + 106
8 libobjc.A.dylib 0x01c85724 -[NSObject performSelector:] + 62
9 CoreFoundation 0x001cd5dc -[NSArray makeObjectsPerformSelector:] + 316
10 UIKit 0x00ddb10a -[UINib instantiateWithOwner:options:] + 1775
11 UIKit 0x00bfd624 -[UIViewController _loadViewFromNibNamed:bundle:] + 270
12 UIKit 0x00bfddbb -[UIViewController loadView] + 295
13 UIKit 0x00bfdfef -[UIViewController loadViewIfRequired] + 78
14 UIKit 0x00bfe595 -[UIViewController view] + 35
15 UIKit 0x01271707 -[_UIFullscreenPresentationController _setPresentedViewController:] + 75
16 UIKit 0x00bd3a81 -[UIPresentationController initWithPresentedViewController:presentingViewController:] + 113
17 UIKit 0x00c0ba61 -[UIViewController _presentViewController:withAnimationController:completion:] + 2102
18 UIKit 0x00c0e5d2 __62-[UIViewController presentViewController:animated:completion:]_block_invoke + 345
19 UIKit 0x00c0e424 -[UIViewController presentViewController:animated:completion:] + 224
20 UIKit 0x00c130be -[UIViewController _showViewController:withAction:sender:] + 213
21 UIKit 0x00e4f3b5 -[UIStoryboardShowSegue perform] + 143
22 UIKit 0x010c3b49 -[UIStoryboardSegueTemplate _perform:] + 217
23 UIKit 0x010c3bc5 -[UIStoryboardSegueTemplate perform:] + 116
24 libobjc.A.dylib 0x01c857cd -[NSObject performSelector:withObject:withObject:] + 84
25 UIKit 0x00aa823d -[UIApplication sendAction:to:from:forEvent:] + 99
26 UIKit 0x00aa81cf -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64
27 UIKit 0x00bdbe86 -[UIControl sendAction:to:forEvent:] + 69
28 UIKit 0x00bdc2a3 -[UIControl _sendActionsForEvents:withEvent:] + 598
29 UIKit 0x00bdb50d -[UIControl touchesEnded:withEvent:] + 660
30 UIKit 0x00af860a -[UIWindow _sendTouchesForEvent:] + 874
31 UIKit 0x00af90e5 -[UIWindow sendEvent:] + 791
32 UIKit 0x00abe549 -[UIApplication sendEvent:] + 242
33 UIKit 0x00ace37e _UIApplicationHandleEventFromQueueEvent + 20690
34 UIKit 0x00aa2b19 _UIApplicationHandleEventQueue + 2206
35 CoreFoundation 0x001b71df __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
36 CoreFoundation 0x001acced __CFRunLoopDoSources0 + 253
37 CoreFoundation 0x001ac248 __CFRunLoopRun + 952
38 CoreFoundation 0x001abbcb CFRunLoopRunSpecific + 443
39 CoreFoundation 0x001ab9fb CFRunLoopRunInMode + 123
40 GraphicsServices 0x0402724f GSEventRunModal + 192
41 GraphicsServices 0x0402708c GSEventRun + 104
42 UIKit 0x00aa68b6 UIApplicationMain + 1526
43 login excersice 0x000a748e top_level_code + 78
44 login excersice 0x000a74cb main + 43
45 libdyld.dylib 0x023dcac9 start + 1
46 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Write below statement after storing data into
NSUserDefaults
NSUserDefaults.standardUserDefaults().synchronize()