你如何在IOS 5中加入SSZipArchive?

时间:2012-01-25 15:18:48

标签: ios objective-c xcode zip ssziparchive

对于我正在处理的项目,我需要解压缩某些文件。为此,我找到了库SSZipArchive。我将其包含在Xcode 4.2中(右键单击Classes文件夹 - >将文件添加到项目中,在对话框中将“将项目复制到目标组的文件夹中” - 选中复选框)。我包含libz库(我已尝试过libz和zlib1.2.5)。我尝试编译,突然间我有20个错误:

/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:311:1: error: expected identifier or '(' [1]
 @class NSString, Protocol;
 ^    
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:313:19: error: unknown type name 'NSString' [1]
 FOUNDATION_EXPORT NSString *NSStringFromSelector(SEL aSelector);
                   ^
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:314:44: error: unknown type name 'NSString' [1]
 FOUNDATION_EXPORT SEL NSSelectorFromString(NSString *aSelectorName);
                                            ^
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:316:19: error: unknown type name 'NSString' [1]
 FOUNDATION_EXPORT NSString *NSStringFromClass(Class aClass);
                   ^
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:317:43: error: unknown type name 'NSString' [1]
 FOUNDATION_EXPORT Class NSClassFromString(NSString *aClassName);
                                           ^
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:319:19: error: unknown type name 'NSString' [1]
 FOUNDATION_EXPORT NSString *NSStringFromProtocol(Protocol *proto) NS_AVAILABLE(10_5, 2_0);
                   ^
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:319:50: error: unknown type name 'Protocol' [1]
 FOUNDATION_EXPORT NSString *NSStringFromProtocol(Protocol *proto) NS_AVAILABLE(10_5, 2_0);
                                                  ^
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:320:19: error: unknown type name 'Protocol' [1]
 FOUNDATION_EXPORT Protocol *NSProtocolFromString(NSString *namestr) NS_AVAILABLE(10_5, 2_0);
                   ^
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:320:50: error: unknown type name 'NSString' [1]
 FOUNDATION_EXPORT Protocol *NSProtocolFromString(NSString *namestr) NS_AVAILABLE(10_5, 2_0);
                                                  ^
 /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:324:30: error: unknown type name 'NSString' [1]
 FOUNDATION_EXPORT void NSLog(NSString *format, ...) NS_FORMAT_FUNCTION(1,2);
                              ^
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:324:53:{324:53-324:76}: error: format argument not an NSString [3]
 FOUNDATION_EXPORT void NSLog(NSString *format, ...) NS_FORMAT_FUNCTION(1,2);
                                                     ^~~~~~~~~~~~~~~~~~~~~~~
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:85:49: note: instantiated from:
         #define NS_FORMAT_FUNCTION(F,A) __attribute__((format(__NSString__, F, A)))
                                                        ^
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:325:31: error: unknown type name 'NSString' [1]
 FOUNDATION_EXPORT void NSLogv(NSString *format, va_list args) NS_FORMAT_FUNCTION(1,0);
                               ^
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:325:63:{325:63-325:86}: error: format argument not an NSString [3]
 FOUNDATION_EXPORT void NSLogv(NSString *format, va_list args) NS_FORMAT_FUNCTION(1,0);
                                                               ^~~~~~~~~~~~~~~~~~~~~~~
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:85:49: note: instantiated from:
         #define NS_FORMAT_FUNCTION(F,A) __attribute__((format(__NSString__, F, A)))

这些都是核心库中的错误,因此在Xcode中包含库可能会出错。我设法将罪魁祸首缩小到SSZipArchive使用的minizip库(如果我删除该库,错误就会消失,编译器会像它应该的那样运行),但我很难理解为什么这会导致编译器出现这么多问题

2 个答案:

答案 0 :(得分:35)

经过很多头痛之后,我发现了问题所在。原来是_Prefix.pch。我完全看了看,但事实证明我在那里有以下几行:

#import "someclass.h"

这个类正在加载minizip库的.c文件,导致.c文件中包含Objective-C头文件,这是XCode不喜欢的东西。将这些语句包装在#ifdef语句中修复了问题:

#ifdef __OBJC__
   #import "someclass.h"
#endif

答案 1 :(得分:-1)

请参阅以下链接,该链接既适用于iphone,也适用于mac应用程序。 Archive and Unarchive from app