在我正在处理的iPhone应用程序中添加一些新按钮时遇到此错误。不完全确定重复的存在位置。
错误:
重复符号_OBJC_CLASS _ $ _权重: /Users/mflood7356/Library/Developer/Xcode/DerivedData/1RMCalculator-bciansmbawnkrwasgwtkbkdpvswt/Build/Intermediates/1RMCalculator.build/Debug-iphonesimulator/1RMCalculator.build/Objects-normal/x86_64/ViewController.o /Users/mflood7356/Library/Developer/Xcode/DerivedData/1RMCalculator-bciansmbawnkrwasgwtkbkdpvswt/Build/Intermediates/1RMCalculator.build/Debug-iphonesimulator/1RMCalculator.build/Objects-normal/x86_64/Weights.o 重复符号_OBJC_METACLASS _ $ _权重: /Users/mflood7356/Library/Developer/Xcode/DerivedData/1RMCalculator-bciansmbawnkrwasgwtkbkdpvswt/Build/Intermediates/1RMCalculator.build/Debug-iphonesimulator/1RMCalculator.build/Objects-normal/x86_64/ViewController.o /Users/mflood7356/Library/Developer/Xcode/DerivedData/1RMCalculator-bciansmbawnkrwasgwtkbkdpvswt/Build/Intermediates/1RMCalculator.build/Debug-iphonesimulator/1RMCalculator.build/Objects-normal/x86_64/Weights.o ld:架构x86_64的2个重复符号 clang:错误:链接器命令失败,退出代码为1(使用-v查看调用)
Weights.m
#import "Weights.h"
@implementation Weights
static Weights *instance = nil;
+(Weights *)getInstance{
@synchronized(self){
if(instance==nil){
instance= [Weights new];
}
}
return instance;
}
static int totalWeight = 0;
static int fortyFives = 0;
static int thirtyFives = 0;
static int twentyFives = 0;
static int tens = 0;
static int fives = 0;
static int twoPointFives = 0;
+ (int)getTotalWeight {
return totalWeight;
}
+ (void)setTotalWeight:(int)newWeight {
totalWeight = newWeight;
[self computePlates];
}
+ (int)getFortyFives {
return fortyFives;
}
+ (void)setFortyFives:(int)newCount {
fortyFives = newCount;
}
+ (int)getThirtyFives {
return thirtyFives;
}
+ (void)setThirtyFives:(int)newCount {
thirtyFives = newCount;
}
+ (int)getTwentyFives {
return twentyFives;
}
+ (void)setTwentyFives:(int)newCount {
twentyFives = newCount;
}
+ (int)getTens {
return tens;
}
+ (void)setTens:(int)newCount {
tens = newCount;
}
+ (int)getFives {
return fives;
}
+ (void)setFives:(int)newCount {
fives = newCount;
}
+ (int)getTwoPointFives {
return twoPointFives;
}
+ (void)setTwoPointFives:(int)newCount {
twoPointFives = newCount;
}
+ (void)computePlates{
if(totalWeight >= 45){
if(totalWeight == 45){
[self setFortyFives: 0];
[self setThirtyFives: 0];
[self setTwentyFives: 0];
[self setTens: 0];
[self setFives: 0];
[self setTwoPointFives: 0];
}
else{
int workingWeight = totalWeight - 45;
// Do 45s
if(workingWeight >= 90){
int plateCounter = 0;
while(workingWeight >= 90){
workingWeight = workingWeight - 90;
plateCounter = plateCounter + 2;
}
NSLog(@"Number of 45s: %d", plateCounter);
[self setFortyFives:plateCounter];
}
else{
NSLog(@"Number of 45s: 0");
[self setFortyFives: 0];
}
// Do 35s
if(workingWeight >= 70){
int plateCounter = 0;
while(workingWeight >= 70){
workingWeight = workingWeight - 70;
plateCounter = plateCounter + 2;
}
NSLog(@"Number of 35s: %d", plateCounter);
[self setThirtyFives:plateCounter];
}
else{
NSLog(@"Number of 35s: 0");
[self setThirtyFives: 0];
}
// Do 25s
if(workingWeight >= 50){
int plateCounter = 0;
while(workingWeight >= 50){
workingWeight = workingWeight - 50;
plateCounter = plateCounter + 2;
}
NSLog(@"Number of 25s: %d", plateCounter);
[self setTwentyFives:plateCounter];
}
else{
NSLog(@"Number of 25s: 0");
[self setTwentyFives: 0];
}
// Do 10s
if(workingWeight >= 20){
int plateCounter = 0;
while(workingWeight >= 20){
workingWeight = workingWeight - 20;
plateCounter = plateCounter + 2;
}
NSLog(@"Number of 10s: %d", plateCounter);
[self setTens:plateCounter];
}
else{
NSLog(@"Number of 10s: 0");
[self setTens: 0];
}
// Do 5s
if(workingWeight >= 10){
int plateCounter = 0;
while(workingWeight >= 10){
workingWeight = workingWeight - 10;
plateCounter = plateCounter + 2;
}
NSLog(@"Number of 5s: %d", plateCounter);
[self setFives:plateCounter];
}
else{
NSLog(@"Number of 5s: 0");
[self setFives: 0];
}
// Do 2.5s
if(workingWeight >= 5){
int plateCounter = 0;
while(workingWeight >= 5){
workingWeight = workingWeight - 5;
plateCounter = plateCounter + 2;
}
NSLog(@"Number of 2.5s: %d", plateCounter);
[self setTwoPointFives:plateCounter];
}
else{
NSLog(@"Number of 2.5s: 0");
[self setTwoPointFives: 0];
}
if(workingWeight < 5 && workingWeight != 0){
// Print something about not being exact?
NSLog(@"Remaining Working Weight: %d", workingWeight);
}
}
}
else{
[self setFortyFives: 0];
[self setThirtyFives: 0];
[self setTwentyFives: 0];
[self setTens: 0];
[self setFives: 0];
[self setTwoPointFives: 0];
}
}
@end
ViewController.m
#import "ViewController.h"
#import "Weights.h"
#import "Weights.m"
@interface ViewController ()
// Objects represent the text fields
@property (strong, nonatomic) IBOutlet UITextField *weightField;
@property (strong, nonatomic) IBOutlet UITextField *repsField;
// Objectsrepresent the percentage buttons below the fields
@property (strong, nonatomic) IBOutlet id nintyFiveResult;
@property (strong, nonatomic) IBOutlet id nintyResult;
@property (strong, nonatomic) IBOutlet id eightyFiveResult;
@property (strong, nonatomic) IBOutlet id eightyResult;
@property (strong, nonatomic) IBOutlet id seventyFiveResult;
@property (strong, nonatomic) IBOutlet id seventyResult;
@property (strong, nonatomic) IBOutlet id sixtyFiveResult;
@property (strong, nonatomic) IBOutlet id sixtyResult;
// Weight object used to perform the on bar calculation
@property (strong, nonatomic) Weights *weightObj;
// Labels represent the values on the second view
@property (strong, nonatomic) IBOutlet UILabel *resultTitle;
@property (strong, nonatomic) IBOutlet UILabel *fortyFivePlateLabel;
@property (strong, nonatomic) IBOutlet UILabel *thirtyFivePlateLabel;
@property (strong, nonatomic) IBOutlet UILabel *twentyFivePlateLabel;
@property (strong, nonatomic) IBOutlet UILabel *tenPlateLabel;
@property (strong, nonatomic) IBOutlet UILabel *fivePlateLabel;
@property (strong, nonatomic) IBOutlet UILabel *twoFivePlateLabel;
@end
@implementation ViewController
- (void)viewDidLoad{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.weightField.delegate = self;
self.repsField.delegate = self;
self.weightObj = [Weights getInstance];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return NO;
}
/* weightModified: This method is called when the weight field is modified.
If the reps or weight value entered is equal to zero all of the percentage
results will be changed to zero. If valid values are passed in both fields
the percentages of weight will be calculated.
*/
- (IBAction)weightModified:(UITextField *)sender {
NSLog(@"Weight Input Value: %@", sender.text);
NSLog(@"Reps Input Value: %@", self.repsField.text);
if([sender.text isEqualToString:@""] == false && [self.repsField.text isEqualToString:@""] == false){
NSLog(@"Weight Modified in if statement.");
// Gather reps and weight value
int reps = 0;
int weight = 0;
weight = [sender.text intValue];
reps = [self.repsField.text intValue];
NSLog(@"Weight: %d", weight);
NSLog(@"Reps: %d", reps);
int nintyFiveInt = [self oneRepMax :0.95 :reps :weight];
int nintyInt = [self oneRepMax :0.9 :reps :weight];
int eightyFiveInt = [self oneRepMax :0.85 :reps :weight];
int eightyInt = [self oneRepMax :0.8 :reps :weight];
int seventyFiveInt = [self oneRepMax :0.75 :reps :weight];
int seventyInt = [self oneRepMax :0.7 :reps :weight];
int sixtyFiveInt = [self oneRepMax :0.65 :reps :weight];
int sixtyInt = [self oneRepMax :0.6 :reps :weight];
NSString *nintyFiveWeight = [NSString stringWithFormat:@"95%%: %d lbs", nintyFiveInt];
NSString *nintyWeight = [NSString stringWithFormat:@"95%%: %d lbs", nintyInt];
NSString *eightyFiveWeight = [NSString stringWithFormat:@"95%%: %d lbs", eightyFiveInt];
NSString *eightyWeight = [NSString stringWithFormat:@"95%%: %d lbs", eightyInt];
NSString *seventyFiveWeight = [NSString stringWithFormat:@"95%%: %d lbs", seventyFiveInt];
NSString *seventyWeight = [NSString stringWithFormat:@"95%%: %d lbs", seventyInt];
NSString *sixtyFiveWeight = [NSString stringWithFormat:@"95%%: %d lbs", sixtyFiveInt];
NSString *sixtyWeight = [NSString stringWithFormat:@"95%%: %d lbs", sixtyInt];
[self.nintyFiveResult setTitle:nintyFiveWeight forState:UIControlStateNormal];
[self.nintyResult setTitle:nintyWeight forState:UIControlStateNormal];
[self.eightyFiveResult setTitle:eightyFiveWeight forState:UIControlStateNormal];
[self.eightyResult setTitle:eightyWeight forState:UIControlStateNormal];
[self.seventyFiveResult setTitle:seventyFiveWeight forState:UIControlStateNormal];
[self.seventyResult setTitle:seventyWeight forState:UIControlStateNormal];
[self.sixtyFiveResult setTitle:sixtyFiveWeight forState:UIControlStateNormal];
[self.sixtyResult setTitle:sixtyWeight forState:UIControlStateNormal];
}
else{
[self.nintyFiveResult setTitle:@"95%%: 0 lbs" forState:UIControlStateNormal];
[self.nintyResult setTitle:@"90%%: 0 lbs" forState:UIControlStateNormal];
[self.eightyFiveResult setTitle:@"85%%: 0 lbs" forState:UIControlStateNormal];
[self.eightyResult setTitle:@"80%%: 0 lbs" forState:UIControlStateNormal];
[self.seventyFiveResult setTitle:@"75%%: 0 lbs" forState:UIControlStateNormal];
[self.seventyResult setTitle:@"70%%: 0 lbs" forState:UIControlStateNormal];
[self.sixtyFiveResult setTitle:@"65%%: 0 lbs" forState:UIControlStateNormal];
[self.sixtyResult setTitle:@"60%%: 0 lbs" forState:UIControlStateNormal];
}
}
/* repsModified: This method is called when the weight field is modified.
If the reps or weight value entered is equal to zero all of the percentage
results will be changed to zero. If valid values are passed in both fields
the percentages of weight will be calculated.
*/
- (IBAction)repsModified:(UITextField *)sender {
if([sender.text isEqualToString:@""] == false && [self.repsField.text isEqualToString:@""] == false){
NSLog(@"Reps Modified in if statement.");
// Gather reps and weight value
int reps = 0;
int weight = 0;
weight = [self.weightField.text intValue];
reps = [sender.text intValue];
NSLog(@"Weight: %d", weight);
NSLog(@"Reps: %d", reps);
int nintyFiveInt = [self oneRepMax :0.95 :reps :weight];
int nintyInt = [self oneRepMax :0.9 :reps :weight];
int eightyFiveInt = [self oneRepMax :0.85 :reps :weight];
int eightyInt = [self oneRepMax :0.8 :reps :weight];
int seventyFiveInt = [self oneRepMax :0.75 :reps :weight];
int seventyInt = [self oneRepMax :0.7 :reps :weight];
int sixtyFiveInt = [self oneRepMax :0.65 :reps :weight];
int sixtyInt = [self oneRepMax :0.6 :reps :weight];
NSString *nintyFiveWeight = [NSString stringWithFormat:@"95%%: %d lbs", nintyFiveInt];
NSString *nintyWeight = [NSString stringWithFormat:@"95%%: %d lbs", nintyInt];
NSString *eightyFiveWeight = [NSString stringWithFormat:@"95%%: %d lbs", eightyFiveInt];
NSString *eightyWeight = [NSString stringWithFormat:@"95%%: %d lbs", eightyInt];
NSString *seventyFiveWeight = [NSString stringWithFormat:@"95%%: %d lbs", seventyFiveInt];
NSString *seventyWeight = [NSString stringWithFormat:@"95%%: %d lbs", seventyInt];
NSString *sixtyFiveWeight = [NSString stringWithFormat:@"95%%: %d lbs", sixtyFiveInt];
NSString *sixtyWeight = [NSString stringWithFormat:@"95%%: %d lbs", sixtyInt];
[self.nintyFiveResult setTitle:nintyFiveWeight forState:UIControlStateNormal];
[self.nintyResult setTitle:nintyWeight forState:UIControlStateNormal];
[self.eightyFiveResult setTitle:eightyFiveWeight forState:UIControlStateNormal];
[self.eightyResult setTitle:eightyWeight forState:UIControlStateNormal];
[self.seventyFiveResult setTitle:seventyFiveWeight forState:UIControlStateNormal];
[self.seventyResult setTitle:seventyWeight forState:UIControlStateNormal];
[self.sixtyFiveResult setTitle:sixtyFiveWeight forState:UIControlStateNormal];
[self.sixtyResult setTitle:sixtyWeight forState:UIControlStateNormal];
}
else{
[self.nintyFiveResult setTitle:@"95%%: 0 lbs" forState:UIControlStateNormal];
[self.nintyResult setTitle:@"90%%: 0 lbs" forState:UIControlStateNormal];
[self.eightyFiveResult setTitle:@"85%%: 0 lbs" forState:UIControlStateNormal];
[self.eightyResult setTitle:@"80%%: 0 lbs" forState:UIControlStateNormal];
[self.seventyFiveResult setTitle:@"75%%: 0lbs" forState:UIControlStateNormal];
[self.seventyResult setTitle:@"70%%: 0 lbs" forState:UIControlStateNormal];
[self.sixtyFiveResult setTitle:@"65%%: 0 lbs" forState:UIControlStateNormal];
[self.sixtyResult setTitle:@"60%%: 0 lbs" forState:UIControlStateNormal];
}
}
/* oneRepMax: This method is used to compute the one rep according to the values passed
percent: represents the percentages displayed on the screen
numReps: represents the number of reps in the reps field
weightToLift: represents the number in the wieght field
The method returns a float of the weight to be displayed on screen
*/
- (float)oneRepMax:(float) percent :(int) numReps :(int) weightToLift{
float r = (float) numReps;
float w = (float) weightToLift;
float div = r/ 30;
return percent*w*div*10;
}
- (void) printResults:(int) percent :(int) weightOnBar :(Weights*) weightObject{
[self.resultTitle setText:[NSString stringWithFormat:@"%d%%: %d", percent, weightOnBar]];
}
// Percentage Buttons
- (IBAction)clickNintyFive:(id)sender {
int weight = [self.weightField.text intValue];
int reps = [self.repsField.text intValue];
int nintyFiveInt = [self oneRepMax :0.95 :reps :weight];
[self printResults: 95: nintyFiveInt: _weightObj];
}
- (IBAction)clickNinty:(id)sender {
int weight = [self.weightField.text intValue];
int reps = [self.repsField.text intValue];
int nintyFiveInt = [self oneRepMax :0.9 :reps :weight];
[self printResults: 90: nintyFiveInt: _weightObj];
}
- (IBAction)clickEightyFive:(id)sender {
int weight = [self.weightField.text intValue];
int reps = [self.repsField.text intValue];
int nintyFiveInt = [self oneRepMax :0.85 :reps :weight];
[self printResults: 85: nintyFiveInt: _weightObj];
}
- (IBAction)clickEighty:(id)sender {
int weight = [self.weightField.text intValue];
int reps = [self.repsField.text intValue];
int nintyFiveInt = [self oneRepMax :0.8 :reps :weight];
[self printResults: 80: nintyFiveInt: _weightObj];
}
- (IBAction)clickSeventyFive:(id)sender {
int weight = [self.weightField.text intValue];
int reps = [self.repsField.text intValue];
int nintyFiveInt = [self oneRepMax :0.75 :reps :weight];
[self printResults: 75: nintyFiveInt: _weightObj];
}
- (IBAction)clickSeventy:(id)sender {
int weight = [self.weightField.text intValue];
int reps = [self.repsField.text intValue];
int nintyFiveInt = [self oneRepMax :0.7 :reps :weight];
[self printResults: 70: nintyFiveInt: _weightObj];
}
- (IBAction)clickSixtyFive:(id)sender {
int weight = [self.weightField.text intValue];
int reps = [self.repsField.text intValue];
int nintyFiveInt = [self oneRepMax :0.65 :reps :weight];
[self printResults: 65: nintyFiveInt: _weightObj];
}
- (IBAction)clickSixty:(id)sender {
int weight = [self.weightField.text intValue];
int reps = [self.repsField.text intValue];
int nintyFiveInt = [self oneRepMax :0.6 :reps :weight];
[self printResults: 60: nintyFiveInt: _weightObj];
}
@end
答案 0 :(得分:3)
您似乎正在导入&#34; Weights.m&#34;。这几乎肯定是一个错误。您通常只想导入头文件(以&#34; .h&#34;结尾的文件)