我在构建我的应用程序时遇到了苹果 mach-O 链接器错误。但是当我删除我的项目作为我的一个类的目标成员时,错误就消失了。
错误是:
duplicate symbol _password in:
    /Users/gabriellebuytaert/Library/Developer/Xcode/DerivedData/Restaurant-gohpgfsvanqgatbrwgxmorkgaztv/Build/Intermediates/Restaurant.build/Debug-iphonesimulator/Restaurant.build/Objects-normal/i386/AdminAccess.o
    /Users/gabriellebuytaert/Library/Developer/Xcode/DerivedData/Restaurant-gohpgfsvanqgatbrwgxmorkgaztv/Build/Intermediates/Restaurant.build/Debug-iphonesimulator/Restaurant.build/Objects-normal/i386/StaffTVC.o
ld: 1 duplicate symbol for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
课程是:
#import "StaffTVC.h"
@interface StaffTVC ()
@end
@implementation StaffTVC
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
NSString *password = @"staff";
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.password.delegate=self;
    UIColor *color =[UIColor colorWithRed:64.0f/255.0f green:80.0f/255.0f blue:98.0f/255.0f alpha:0.9f];
    [self.navigationController.navigationBar setTintColor:color];
    self.navigationController.navigationBar.alpha = 0.7;
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
    if (textField == self.password){
        [textField resignFirstResponder];
    }
    return YES;
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}
- (IBAction)save:(id)sender
{
    if([password isEqualToString:self.password.text]){
        NSLog(@"Successful login to staff page");
        [self performSegueWithIdentifier:@"Go on to staff page" sender:self];
    }else {
        UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Wrong input" message:@"Re-enter password" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
        [av setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];
        // Alert style customization
        [[av textFieldAtIndex:0] setSecureTextEntry:YES];
        [[av textFieldAtIndex:0] setPlaceholder:@"password"];
        [av show];
    }
    self.password.text= @"";
}
-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    NSString *buttonTitle = [alertView buttonTitleAtIndex:buttonIndex];
    UITextField *passText = [alertView textFieldAtIndex:0];
    if([buttonTitle isEqualToString:@"OK"]){
        if([passText.text isEqualToString:password]){
            [self performSegueWithIdentifier:@"Go on to staff page" sender:self];
        }else{
            UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Wrong input" message:@"Re-enter password" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
            [av setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];
            // Alert style customization
            [[av textFieldAtIndex:0] setSecureTextEntry:YES];
            [[av textFieldAtIndex:0] setPlaceholder:@"password"];
            [av show];
        }
    }else if([buttonTitle isEqualToString:@"Cancel"]){
    }
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"Go on to staff page"])
    {
    }
}
@end