Sorry for such a simple question, but I have yet to find a simple explanation for editing/changing core data attributes via code rather than GUI.
Essentially, I have a master-detail window with a list of users and their attributes, respectively. One of the details is password field where a user can set their password. As soon as control leaves the text box, I want to replace the password just entered by the user (now saved by core data into the application's data store) with the MD5 digest of the password.
(I created the data model graphically in Xcode and am using SSCrypto.)
Here's what I have.
// Saves hash of user's password. - (void)controlTextDidEndEditing:(NSNotification *)aNotification { NSString *password = [[aNotification object] stringValue];
SSCrypto *crypto = [SSCrypto alloc]; [crypto setClearTextWithString:password];
NSString *passwordHash = [[crypto digest:@"MD5"] hexdump];
// Here's where I go astray. NSManagedObject *user = nil; user = [NSEntityDescription entityForName:@"User" inManagedObjectContext: [TestAppDelegate managedObjectContext]];
[user setValue: passwordHash forKey: @"password"];
}
A. Am I getting a reference to the User managed object correctly? B. If so, how to I set the password for the selected (in master) User? Xcode mentions that the selector is unrecognized. How can I make it so that the selector point to the currently selected user?
Thanks for any insight.
- Jeremiah Atwood |