我正在创建一个多用户 iPhone 应用程序,并且正在尝试完成用户登录过程中的编码。我可以成功创建一个帐户,并将用户输入的数据存储到 Core Data DB 中,并将 pin 存储到 Keychain 中,所以现在我正在尝试完成登录过程。下面列出的以下代码是我到目前为止所拥有的,我收到一个错误,“帐户”没有可见的@interface 声明选择器“密码:”
- (IBAction)processLogin:(id)sender {
// hide keyboard
[_textFieldUsername resignFirstResponder];
[_textFieldPin resignFirstResponder];
// First - make activity indicator visible, then start animating, then turn of wrong user / pin label
_welcomeActivityIndicator.hidden = FALSE;
[_welcomeActivityIndicator startAnimating];
[_wrongUserPin setHidden:YES];
// check if username and pin text fields are populated
if ([_textFieldUsername.text length ] == 0 && [_textFieldPin.text length ] == 0)
{
[_welcomeActivityIndicator stopAnimating];
[_wrongUserPin setHidden:NO];
}
// CORE DATA
// NSManagedObjectContext *context = _managedObjectContext;
NSFetchRequest *request= [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Account" inManagedObjectContext:_managedObjectContext];
NSPredicate *predicate =[NSPredicate predicateWithFormat:@"username=%@",self.textFieldUsername.text];
// TODO check pin
Account *pinAccount = [[Account alloc] init];
// GETTING ERROR ON BELOW LINE OF CODE! - ERR0R - No visible @interface for 'Account' declares the selector 'password:'
[pinAccount password:_textFieldPin.text];
[request setEntity:entity];
[request setPredicate:predicate];
NSError *error = nil;
NSArray *array = [_managedObjectContext executeFetchRequest:request error:&error];
if (array != nil) {
NSUInteger count = [array count]; // may be 0 if the object has been deleted.
NSLog(@"Username may exist, %@",count);
}
else {
NSLog(@"Username does not exist.");
}
}
Account 类文件m和h如下所示:
帐户.m
- (NSString*)password
{
if (self.username)
return [KeychainHelper getPasswordForKey:self.username];
return nil;
}
- (void)setPassword:(NSString*)aPassword
{
if (self.username) [KeychainHelper setPassword:aPassword forKey:self.username];
}
- (void)prepareForDeletion
{
if (self.username) [KeychainHelper removePasswordForKey:self.username];
}
@end
帐户.h
#import "AccountBase.h"
@interface Account : AccountBase {
}
// nonatomic - don't worry about multithreading
@property (nonatomic, assign) NSString *password;
- (void)setPassword:(NSString*)aPassword;
@end
我将不胜感激任何想法或想法,并感谢您的阅读。