Objective-C中,分类的问题
最近在学习OC,遇到了一些问题,想问高手如何解决。
------------以下是Fraction.h文件内容------------------
#import <Foundation/Foundation.h>
@interface Fraction : NSObject
-(void) print;
-(double) convertToNum;
-(void) setTo: (int)n Over:(int)d;
-(void) reduce;
@property int numerator, denominator;
@end
------------以下是Fraction.m文件内容------------------
#import "Fraction.h"
@implementation Fraction
{
}
@synthesize numerator, denominator;
-(Fraction *)initWith:(int)n over:(int)d{
//具体实现省略
}
-(void) reduce{
//具体实现省略
}
-(void) print{
//具体实现省略
}
-(double) convertToNum{
//具体实现省略
}
-(void) setTo:(int)n Over:(int)d{
//具体实现省略
}
@end
-------------以下是Fraction+Ops.h的内容-------------
#import "Fraction.h"
@interface Fraction (MathOps)
-(Fraction *)add:(Fraction *)f;
-(Fraction *)mul:(Fraction *)f;
-(Fraction *)sub:(Fraction *)f;
-(Fraction *)div:(Fraction *)f;
@end
----------以下是Fraction+Ops.m的内容-------------
#import "Fraction+MathOps.h"
#import "Fraction.m"
@implementation Fraction (MathOps)
-(Fraction *) add:(Fraction *)f{
//具体实现省略
}
-(Fraction *)sub:(Fraction *)f{
//具体实现省略
}
-(Fraction *)mul:(Fraction *)f{
//具体实现省略
}
-(Fraction *)div:(Fraction *)f{
//具体实现省略
}
@end
现在的问题是,已经确定实现的代码没有错误,但是编译的时候,提示编译失败。错误信息如下:
Ld /Users/czclk/Library/Developer/Xcode/DerivedData/HelloWorld-bptlkzckpfrvvkdgxolkkdxzrthb/Build/Products/Debug/HelloWorld normal x86_64
cd /Users/czclk/Desktop/HelloWorld/HelloWorld
setenv MACOSX_DEPLOYMENT_TARGET 10.8
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -L/Users/czclk/Library/Developer/Xcode/DerivedData/HelloWorld-bptlkzckpfrvvkdgxolkkdxzrthb/Build/Products/Debug -F/Users/czclk/Library/Developer/Xcode/DerivedData/HelloWorld-bptlkzckpfrvvkdgxolkkdxzrthb/Build/Products/Debug -filelist /Users/czclk/Library/Developer/Xcode/DerivedData/HelloWorld-bptlkzckpfrvvkdgxolkkdxzrthb/Build/Intermediates/HelloWorld.build/Debug/HelloWorld.build/Objects-normal/x86_64/HelloWorld.LinkFileList -mmacosx-version-min=10.8 -fobjc-arc -framework Foundation -o /Users/czclk/Library/Developer/Xcode/DerivedData/HelloWorld-bptlkzckpfrvvkdgxolkkdxzrthb/Build/Products/Debug/HelloWorld
duplicate symbol _OBJC_IVAR_$_Fraction.numerator in:
/Users/czclk/Library/Developer/Xcode/DerivedData/HelloWorld-bptlkzckpfrvvkdgxolkkdxzrthb/Build/Intermediates/HelloWorld.build/Debug/HelloWorld.build/Objects-normal/x86_64/Fraction.o
/Users/czclk/Library/Developer/Xcode/DerivedData/HelloWorld-bptlkzckpfrvvkdgxolkkdxzrthb/Build/Intermediates/HelloWorld.build/Debug/HelloWorld.build/Objects-normal/x86_64/Fraction+MathOps.o
duplicate symbol _OBJC_IVAR_$_Fraction.denominator in:
/Users/czclk/Library/Developer/Xcode/DerivedData/HelloWorld-bptlkzckpfrvvkdgxolkkdxzrthb/Build/Intermediates/HelloWorld.build/Debug/HelloWorld.build/Objects-normal/x86_64/Fraction.o
/Users/czclk/Library/Developer/Xcode/DerivedData/HelloWorld-bptlkzckpfrvvkdgxolkkdxzrthb/Build/Intermediates/HelloWorld.build/Debug/HelloWorld.build/Objects-normal/x86_64/Fraction+MathOps.o
duplicate symbol _OBJC_CLASS_$_Fraction in:
/Users/czclk/Library/Developer/Xcode/DerivedData/HelloWorld-bptlkzckpfrvvkdgxolkkdxzrthb/Build/Intermediates/HelloWorld.build/Debug/HelloWorld.build/Objects-normal/x86_64/Fraction.o
/Users/czclk/Library/Developer/Xcode/DerivedData/HelloWorld-bptlkzckpfrvvkdgxolkkdxzrthb/Build/Intermediates/HelloWorld.build/Debug/HelloWorld.build/Objects-normal/x86_64/Fraction+MathOps.o
duplicate symbol _OBJC_METACLASS_$_Fraction in:
/Users/czclk/Library/Developer/Xcode/DerivedData/HelloWorld-bptlkzckpfrvvkdgxolkkdxzrthb/Build/Intermediates/HelloWorld.build/Debug/HelloWorld.build/Objects-normal/x86_64/Fraction.o
/Users/czclk/Library/Developer/Xcode/DerivedData/HelloWorld-bptlkzckpfrvvkdgxolkkdxzrthb/Build/Intermediates/HelloWorld.build/Debug/HelloWorld.build/Objects-normal/x86_64/Fraction+MathOps.o
ld: 4 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
请问高手如何解决,问题出在哪儿了呢?谢谢!!!!
[解决办法]
问题出在: #import "Fraction.m"
请不要import .m