I created an object for a make believe user that stores the username and password, I then put the object in a dictionary. Now I'm trying to store the dictionary using NSUserDefault but its not letting me. I understand its best not to use NSUserDefault to store user data but this is just beginner stuff I'm trying to learn.
/**interface file **/
#import "newUser.h"
@interface BWViewController : UIViewController
{
IBOutlet UITextField *userNameField;
IBOutlet UITextField *passwordField;
IBOutlet UILabel * loginStatus;
}
@property (nonatomic, copy) NSDictionary * aUser;
-(IBAction)signUpButton;
@end
/**implementation file**/
@interface BWViewController ()
@end
@implementation BWViewController
@synthesize aUser;
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
-(IBAction) signUpButton
{
newUser * firstUser = [[newUser alloc] init];
firstUser.userName = userNameField.text;
firstUser.password = passwordField.text;
NSLog(@"%@", firstUser.userName); /**for testing**/
NSLog(@"%@", firstUser.password); /**for testing**/
aUser = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:firstUser, nil] forKeys:[NSArray arrayWithObjects:userNameField.text, nil]];
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:aUser forKey:userNameField.text];
[defaults synchronize];
loginStatus.text = @"Thanks for signing up!";
}