在尝试编译和运行我的项目时,我遇到了上面的错误。这是一个更详细的外观:
duplicate symbol _timeTick in:
/Users/zstephen/Library/Developer/Xcode/DerivedData/MyStore_2-ejjgywkgxdulkogcohzbzojgqpzp/Build/Intermediates/MyStore 2.build/Debug-iphonesimulator/MyStore.build/Objects-normal/i386/TimeController.o
/Users/zstephen/Library/Developer/Xcode/DerivedData/MyStore_2-ejjgywkgxdulkogcohzbzojgqpzp/Build/Intermediates/MyStore 2.build/Debug-iphonesimulator/MyStore.build/Objects-normal/i386/DeviceDetailViewController.o
ld: 1 duplicate symbol for architecture i386
clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
我该如何解决这个问题?提前致谢!
更新:这是使用 timeTick 的 3 个文件:
。H:
#import <UIKit/UIKit.h>
int timeTick = 0;
@interface TimeController : UIViewController{
IBOutlet UILabel *labelTime;
}
- (IBAction)startTimer:(id)sender;
@end
米:
@implementation TimeController
NSTimer *timer;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
labelTime.text = @"0";
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)startTimer:(id)sender {
[timer invalidate];
timer= [NSTimer scheduledTimerWithTimeInterval:60.0 target:(self) selector: (@selector(tick)) userInfo:(nil) repeats:(YES)];
}
-(void)tick{
timeTick++;
NSString *timeString = [[NSString alloc] initWithFormat:@"%d", timeTick];
labelTime.text = timeString;
}
@end
最后,有一个单独的文件将 timeTick 保存并加载到 Core Data 中。
米:
NSNumber *timetickNumber = [NSNumber numberWithInt:timeTick];
[newDevice setValue:timetickNumber forKey:@"name"];