GData ObjC - 重复的接口定义错误

时间:2012-04-29 07:36:42

标签: iphone objective-c ios xcode cocoa-touch

我正在尝试使用GData ObjC库将视频从iPhone上传到Youtube。

当我在添加库后尝试构建项目时(出现在这里: svn checkout http://gdata-objectivec-client.googlecode.com/svn/trunk/gdata-objectivec-client-read-only),我不断收到错误 - 类'GDataHTTPUploadFetcher的重复接口定义' - 在GDataServiceBase.m中。

然而,当我在一个新项目中做同样的事情时,我根本不会遇到任何问题。我检查了所有的导入和项目设置,它们都是一样的。

我应该寻找什么来解决这个问题?


其他信息:

(在评论中回答Till的一个问题,因为我不完全确定类别)

GDataHTTPUploadFetcher.h 中,界面如下:

@interface GDataHTTPUploadFetcher : GDataHTTPFetcher {

GDataHTTPFetcher *chunkFetcher_;
BOOL needsManualProgress_
NSURL *locationURL_;
// uploadData_ or uploadFileHandle_ may be set, but not both
NSData *uploadData_;
NSFileHandle *uploadFileHandle_;
NSInteger uploadFileHandleLength_;
NSString *uploadMIMEType_;
NSUInteger chunkSize_;
BOOL isPaused_;

.
.
.

}

+ (GDataHTTPUploadFetcher *)uploadFetcherWithRequest:(NSURLRequest *)request
                                      uploadData:(NSData *)data
                                  uploadMIMEType:(NSString *)uploadMIMEType
                                       chunkSize:(NSUInteger)chunkSize;

+ (GDataHTTPUploadFetcher *)uploadFetcherWithRequest:(NSURLRequest *)request
                                uploadFileHandle:(NSFileHandle *)fileHandle
                                  uploadMIMEType:(NSString *)uploadMIMEType
                                       chunkSize:(NSUInteger)chunkSize;

- (id)initWithRequest:(NSURLRequest *)request
       uploadData:(NSData *)data
 uploadFileHandle:(NSFileHandle *)fileHandle
   uploadMIMEType:(NSString *)uploadMIMEType
        chunkSize:(NSUInteger)chunkSize;

- (void)pauseFetching;
- (void)resumeFetchingWithDelegate:(id)delegate;
- (BOOL)isPaused;



@end

GDataHTTPUploadFetcher.m 中,界面如下:

@interface GDataHTTPUploadFetcher (InternalMethods)
- (void)uploadNextChunkWithOffset:(NSUInteger)offset;
- (void)uploadNextChunkWithOffset:(NSUInteger)offset
            fetcherProperties:(NSDictionary *)props;
- (void)destroyChunkFetcher;

- (void)uploadFetcher:(GDataHTTPFetcher *)fetcher
     didSendBytes:(NSInteger)bytesSent
   totalBytesSent:(NSInteger)totalBytesSent
totalBytesExpectedToSend:(NSInteger)totalBytesExpected;

- (void)reportProgressManually;

- (NSUInteger)fullUploadLength;

// private methods of the superclass
- (void)invokeSentDataCallback:(SEL)sel
                    target:(id)target
           didSendBodyData:(NSInteger)bytesWritten
         totalBytesWritten:(NSInteger)totalBytesWritten
 totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite;

- (void)invokeStatusCallback:(SEL)sel
                  target:(id)target
                  status:(NSInteger)status
                    data:(NSData *)data;

- (BOOL)invokeRetryCallback:(SEL)sel
                 target:(id)target
              willRetry:(BOOL)willRetry
                  error:(NSError *)error;
@end

GDataServiceBase.m 中,界面如下:

@interface GDataHTTPUploadFetcher : GDataHTTPFetcher
+ (GDataHTTPUploadFetcher *)uploadFetcherWithRequest:(NSURLRequest *)request
                                      uploadData:(NSData *)data
                                  uploadMIMEType:(NSString *)uploadMIMEType
                                       chunkSize:(NSUInteger)chunkSize;
+ (GDataHTTPUploadFetcher *)uploadFetcherWithRequest:(NSURLRequest *)request
                                uploadFileHandle:(NSFileHandle *)uploadFileHandle
                                  uploadMIMEType:(NSString *)uploadMIMEType
                                       chunkSize:(NSUInteger)chunkSize;
- (void)pauseFetching;
- (void)resumeFetchingWithDelegate:(id)delegate;
- (BOOL)isPaused;
@end

但问题是,此代码只会在其中一个现有项目中产生问题,而不会在新项目中产生问题。

3 个答案:

答案 0 :(得分:0)

检查您的目标 - > 构建阶段 - > 编译来源可能包含GDataServiceBase.m两次。如果是,请从该列表中删除一个引用。

enter image description here

还要彻底检查所有导入/包含,看看那些可能包含实现文件(.m)。 GDataServiceBase.m上的全局搜索将完成这项工作。

也许您在标题中的某处使用了#include而不是#import。现在,如果您这样做,包含该标头的标头或实现文件中的另一个#include相同标头将导致双重定义。即使没有守护定义,#import也能完美地工作,而#include需要那些来防止双重定义。

发布代码后,很明显。你引用的那些来源显然是双重定义同一个类。我只能猜测推理; 直接糟糕的设计


最后,原因

显然GDataServiceBase.m以及GDataHTTPUploadFetcher.h定义了同一个类:GDataHTTPUploadFetcher。这当然没有意义。我不能回答为什么作者这样做,也许它只是一个过时的实现文件,不应该再编译。无论如何,只需从@interface移除整个GDataServiceBase.m块,直到并包括第一个@end。 第三个接口定义(在GDataHTTPUploadFetcher.m内)实际上定义了一个类别 - 您可以看到它,因为它包含类/类别名称(InternalMethods)后面的括号。顺便说一句,原作者不应该将它们命名为InternalMethods,而只需打开并关闭括号()即可。但这里的一切都是他的错,不是你的错:D。

答案 1 :(得分:0)

要使用GData ObjC库,请参阅this链接。按照步骤。这很简单。

答案 2 :(得分:0)

我必须将所有代码移动到一个新项目,然后一切正常。

显然,我在项目设置中弄乱了一些东西。

非常感谢所有人的帮助。