你能指导我如何正确地将静态库链接到iPhone项目.我使用添加到app项目的静态库项目作为直接依赖(目标 - >一般 - >直接依赖)并且所有工作正常,但是类别.静态库中定义的类别在app中不起作用.
所以我的问题是如何将静态库与一些类别添加到其他项目中?
一般来说,在其他项目的应用程序项目代码中使用的最佳做法是什么?
我已经创建了一个静态库来存放我的一些代码,比如类别.
我在"UIView-Extensions.h"中有一个名为Extensions的UIViews类别.
在这个类别中我有一个叫做的方法:
- (void)fadeOutWithDelay:(CGFloat)delay duration:(CGFloat)duration;
Run Code Online (Sandbox Code Playgroud)
调用此方法在Debug配置的模拟器上运行正常.
但是,如果尝试在设备上运行应用程序,我会收到NSInvalidArgumentException:
[UIView fadeOutWithDelay:duration:]: unrecognized selector sent to instance 0x1912b0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIView fadeOutWithDelay:duration:]: unrecognized selector sent to instance 0x1912b0
Run Code Online (Sandbox Code Playgroud)
似乎由于某种原因UIView-Extensions.h没有被包含在设备构建中.
我检查/尝试了什么
我确实尝试为NSString包含另一个类别,并且遇到了同样的问题.
其他文件,如整个类和函数都可以正常工作.这是一个仅在类别中出现的问题.
我做了一个干净的所有目标,但没有解决问题.
我检查了静态库项目,这些类别包含在目标的"copy headers"和"compile sources"组中.
静态库包含在主项目"链接二进制文件库"组中.
我添加静态库的另一个项目工作得很好.
我删除并重新添加静态库,没有运气
-ObjC链接器标志已设置
有任何想法吗?
nm输出
libFJSCodeDebug.a(UIView-Extensions.o):
000004d4 t -[UIView(Extensions) changeColor:withDelay:duration:]
00000000 t -[UIView(Extensions) fadeInWithDelay:duration:]
000000dc t -[UIView(Extensions) fadeOutWithDelay:duration:]
00000abc t -[UIView(Extensions) firstResponder]
000006b0 t -[UIView(Extensions) hasSubviewOfClass:]
00000870 t -[UIView(Extensions) hasSubviewOfClass:thatContainsPoint:]
000005cc t -[UIView(Extensions) rotate:]
000002d8 …Run Code Online (Sandbox Code Playgroud) 首先,我看到有很多关于"无法识别的选择器发送到实例"的问题.
我见过很少,但没有看到访问类别属性中定义的...
我在UILabel上有一个属性的类别.
确定了getter和setter.
实际上我在2个不同的类别中拥有相同的属性(对于2个不同的类别:UIButton和UILabel).
问题是我可以为UIButton访问此属性,但不能访问UILabel.
一旦我尝试访问UILabel(文本)类别中的任何方法/属性,它就会删除" - [UILabel test]:无法识别的选择器发送到实例0x4e539f0"异常.
两个类别文件都已导入.
我不知道是什么问题.
这是一些代码:
// UILabel+text.h
@interface UILabel (text)
- (void)test;
@end
// UILabel+text.m
@implementation UILabel (text)
- (void)test {
NSLog(@"test");
}
@end
// UIButton+text.h
@interface UIButton (text)
- (void)test;
@end
// UIButton+text.m
@implementation UIButton (text)
- (void)test {
NSLog(@"test");// works
}
@end
// Usage (in UIViewController class) - both elements are defined in XIB
[self.button test];// works
[self.label test];// exception
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.
我不知道可能出现的问题......
谢谢.
迈克尔.
iphone objective-c unrecognized-selector objective-c-category
这是一个iOS问题.
我构建了一个静态库(iOS中的框架),然后将其包含在应用程序中.结果二进制(500kb)的大小小于静态库(6mb)的大小.这是如何运作的?我对静态库的理解是静态库包含在最终的二进制文件中
可能重复:
-all_load链接器标志有什么作用?
我看到大多数静态库都要求你这样做,所以我将它们添加到我的所有项目中,添加这个似乎没有副作用?
假设今天是2014年1月20日.如果我使用NSDataDetector从字符串"明天下午4点"中提取日期,我将得到2014-01-21T16:00.大.
但是,假设我希望NSDataDetector 假装当前日期是2014年1月14日.这样,当我解析"明天下午4点"时,我会得到2014-01-15T16:00.如果我在设备上更改系统时间,我会得到我想要的.但是,有没有办法以编程方式指定它?
谢谢.
添加OCMock框架后我得到了那个奇怪的错误...... :(
ld: file not found: -fobjc-arc clang: error: linker command failed with exit code 1 (use -v to see invocation)
看起来编译器标志是否试图由XCode加载?
任何的想法?
最好的问候,hijolan
我现在已经打了几个小时了,我已经厌倦了.我的项目可以通过调试模拟器构建,发布模拟器构建和调试设备构建来构建,但由于某种原因,它不会使用发布设备构建构建.我有一个包含我的cocos2d代码的静态库,以及另一个包含我编写的游戏引擎的静态库.
因为游戏引擎包含类别,所以我不得不使用all_load链接器标志来运行它.没有这个标志,代码构建正常.但是,当我尝试运行游戏时,我收到一个无法识别的选择器发送到实例异常.
这是第一个构建错误:
ld: duplicate symbol _OBJC_CLASS_$_FontLabel in /Users/helixed/Dropbox/Documents/Development/iPhone/Cocos2d/build/Release-iphoneos/libcocos2d.a(FontLabel.o) and /Users/helixed/Dropbox/Documents/Development/iPhone/Cocos2d/build/Release-iphoneos/libcocos2d.a(FontLabel.o)
Ld build/Shapeless.build/Release-iphoneos/Shapeless.build/Objects-normal/armv6/Shapeless normal armv6
cd /Users/helixed/Dropbox/Documents/Development/iPhone/Apps/Shapeless
setenv IPHONEOS_DEPLOYMENT_TARGET 4.0
setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/llvm-g++-4.2 -arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk -L/Users/helixed/Dropbox/Documents/Development/iPhone/Apps/Shapeless/build/Release-iphoneos -F/Users/helixed/Dropbox/Documents/Development/iPhone/Apps/Shapeless/build/Release-iphoneos -filelist /Users/helixed/Dropbox/Documents/Development/iPhone/Apps/Shapeless/build/Shapeless.build/Release-iphoneos/Shapeless.build/Objects-normal/armv6/Shapeless.LinkFileList -dead_strip -ObjC -all_load -miphoneos-version-min=4.0 /Users/helixed/Dropbox/Documents/Development/iPhone/Cocos2d/build/Release-iphoneos/libChipmunk.a /Users/helixed/Dropbox/Documents/Development/iPhone/Cocos2d/build/Release-iphoneos/libcocos2d.a /Users/helixed/Dropbox/Documents/Development/iPhone/BlackHawk/build/Release-iphoneos/libBlackHawk.a -framework Foundation -framework UIKit -framework CoreGraphics -framework QuartzCore -framework OpenGLES -framework OpenAL -framework AVFoundation -framework AudioToolbox -lz -framework iAd -o /Users/helixed/Dropbox/Documents/Development/iPhone/Apps/Shapeless/build/Shapeless.build/Release-iphoneos/Shapeless.build/Objects-normal/armv6/Shapeless
ld: duplicate symbol _OBJC_CLASS_$_FontLabel in /Users/helixed/Dropbox/Documents/Development/iPhone/Cocos2d/build/Release-iphoneos/libcocos2d.a(FontLabel.o) and /Users/helixed/Dropbox/Documents/Development/iPhone/Cocos2d/build/Release-iphoneos/libcocos2d.a(FontLabel.o)
collect2: ld returned 1 exit status
Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/llvm-g++-4.2 failed with exit code …Run Code Online (Sandbox Code Playgroud) 我正在创建一个ios项目,我在其中添加了推送通知的解析,因此需要将其他链接器标志设置为空,但是当我将其他链接器标志设置为空时,在运行时推送视图控制器时出现以下错误
2014-09-06 21:16:04.739 Guess_Funny_Emoji [9100:a0b] + [NSDecimalNumber gad_negativeOne]:无法识别的选择器发送到类0x2c84c18 2014-09-06 21:16:04.743 Guess_Funny_Emoji [9100:a0b]由于未捕获的异常而终止应用'NSInvalidArgumentException',原因:'+ [NSDecimalNumber gad_negativeOne]:无法识别的选择器发送到类0x2c84c18'
当我通过-ObjC设置其他链接器标志时,则发生解析错误,如下所示
对于架构的i386未定义的符号: "_FBTokenInformationExpirationDateKey",从参考: - [PFFacebookTokenCachingStrategy cacheTokenInformation:]在ParseFacebookUtils(PFFacebookTokenCachingStrategy.o) - 在ParseFacebookUtils [PFFacebookTokenCachingStrategy EXPIRATIONDATE](PFFacebookTokenCachingStrategy.o) - [PFFacebookTokenCachingStrategy setExpirationDate:]在ParseFacebookUtils(PFFacebookTokenCachingStrategy.o ) "_FBTokenInformationTokenKey",从参考: - [PFFacebookTokenCachingStrategy的accessToken]在ParseFacebookUtils(PFFacebookTokenCachingStrategy.o) - [PFFacebookTokenCachingStrategy setAccessToken:]在ParseFacebookUtils(PFFacebookTokenCachingStrategy.o) "_FBTokenInformationUserFBIDKey",从参考: - [PFFacebookTokenCachingStrategy facebookId]在ParseFacebookUtils(PFFacebookTokenCachingStrategy. o) - ParseFacebookUtils(PFFacebookTokenCachingStrategy.o)中的[PFFacebookTokenCachingStrategy setFacebookId:]"_ OBJC_CLASS _ $ _ FBAppCall",引自:objc-class-ref in ParseFacebookUtils(PFFacebookAuthenticationProvider.o) "_OBJC_CLASS _ $ _ FBSession",从引用:objc级-REF在ParseFacebookUtils(PFFacebookAuthenticationProvider.o) "_OBJC_CLASS _ $ _ FBSessionTokenCachingStrategy",从引用:在ParseFacebookUtils _OBJC_CLASS _ $ _ PFFacebookTokenCachingStrategy(PFFacebookTokenCachingStrategy.o)"_OBJC_METACLASS _ $ _ FBSessionTokenCachingStrategy ",引自:_ PJF_METACLASS _ $ _ PFFacebookTokenCachingStrategy in ParseFacebookUtils(PFFacebookTokenCachingStrategy.o)ld:符号未找到架构i386 clang:错误:链接器命令失败,退出代码为1(使用-v查看调用)
所以请帮我解决这个问题
我正在开发一个iPhone应用程序.我对Xcode不熟悉,所以请耐心等待.我有iOS 4.1 Device SDK.当我在"Active ..."下拉框中选择"Simulator"时,我的应用程序编译没有错误并在iPhone模拟器中运行.
但是,当我在下拉框中选择"设备"时,我收到有关重复符号的以下链接器错误:
Ld build/PineCone.build/Debug-iphoneos/PineCone.build/Objects-normal/armv6/PineCone normal armv6
cd /Users/isaacsutherland/fydp/PineCone/PineCone
setenv IPHONEOS_DEPLOYMENT_TARGET 4.1
setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.1.sdk -L/Users/isaacsutherland/fydp/PineCone/PineCone/build/Debug-iphoneos -L/Users/isaacsutherland/fydp/PineCone/PineCone/../3rd/libGHUnitIPhone -F/Users/isaacsutherland/fydp/PineCone/PineCone/build/Debug-iphoneos -filelist /Users/isaacsutherland/fydp/PineCone/PineCone/build/PineCone.build/Debug-iphoneos/PineCone.build/Objects-normal/armv6/PineCone.LinkFileList -dead_strip -all_load -ObjC -miphoneos-version-min=4.1 -framework Foundation -framework UIKit -framework CoreGraphics /Users/isaacsutherland/fydp/PineCone/3rd/three20/Build/Products/Debug-iphoneos/libThree20.a /Users/isaacsutherland/fydp/PineCone/3rd/three20/Build/Products/Debug-iphoneos/libThree20Core.a /Users/isaacsutherland/fydp/PineCone/3rd/three20/Build/Products/Debug-iphoneos/libThree20Network.a /Users/isaacsutherland/fydp/PineCone/3rd/three20/Build/Products/Debug-iphoneos/libThree20Style.a /Users/isaacsutherland/fydp/PineCone/3rd/three20/Build/Products/Debug-iphoneos/libThree20UI.a /Users/isaacsutherland/fydp/PineCone/3rd/three20/Build/Products/Debug-iphoneos/libThree20UICommon.a /Users/isaacsutherland/fydp/PineCone/3rd/three20/Build/Products/Debug-iphoneos/libThree20UINavigator.a -framework QuartzCore -framework CFNetwork -framework MobileCoreServices -framework SystemConfiguration -lz.1.2.3 /Users/isaacsutherland/fydp/PineCone/ClientDal/build/Debug-iphoneos/libClientDal.a -lGHUnitIPhone4_0 -o /Users/isaacsutherland/fydp/PineCone/PineCone/build/PineCone.build/Debug-iphoneos/PineCone.build/Objects-normal/armv6/PineCone
ld: duplicate symbol _RedirectionLimit in /Users/isaacsutherland/fydp/PineCone/ClientDal/build/Debug-iphoneos/libClientDal.a(libASIHTTPRequest.a-armv6-master.o) and /Users/isaacsutherland/fydp/PineCone/ClientDal/build/Debug-iphoneos/libClientDal.a(libASIHTTPRequest.a-armv6-master.o)
collect2: ld returned 1 exit status
Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1
Run Code Online (Sandbox Code Playgroud)
错误是奇怪的,因为它抱怨_RedirectionLimit被发现两次 …
objective-c ×7
ios ×6
iphone ×6
xcode ×5
build ×2
c ×1
categories ×1
cocoa-touch ×1
exception ×1
ios4 ×1
linker ×1
nsdate ×1
xcodebuild ×1