Strong dispatch_queue_t in CocoaPods library

不打扰是莪最后的温柔 提交于 2020-01-13 19:41:30

问题


In a library that may be built with an iOS 5.x/OS X 10.7 deployment target or with a newer one I had a problem for properly defining a dispatch_queue_t property.

For the most part I could solve it as suggested here:

#if OS_OBJECT_HAVE_OBJC_SUPPORT // == 1 not really needed
@property (nonatomic, strong) dispatch_queue_t loggerQueue; // An Objective-C object
#else
@property (nonatomic, assign) dispatch_queue_t loggerQueue; // A C pointer
#endif

This works when manually creating a static library or when including the file directly in a project.

When this code is added to a CocoaPods library however it breaks for iOS 6+/OS X 10.8+ deployment targets. CocoaPods properly sets the deployment targets and the compiler do sets OS_OBJECT_HAVE_OBJC_SUPPORT == 1 and chooses the strong definition. I get however the iOS 5.x/OS X 10.7 error:

Property with 'retain (or strong)' attribute must be of object type

I tried comparing the resulting environment variables between CocoaPods and the static library but there's nothing that seems suspicious.

For now I have patched it by disabling the strong definition altogether when building with CocoaPods:

#if OS_OBJECT_HAVE_OBJC_SUPPORT && !defined(COCOAPODS)
@property (nonatomic, strong) dispatch_queue_t loggerQueue; // Always disabled
#else
@property (nonatomic, assign) dispatch_queue_t loggerQueue;
#endif

回答1:


Seems like older CocoaPods was redefining OS_OBJECT_USE_OBJC breaking OS_OBJECT_HAVE_OBJC_SUPPORT.

We got this fixed by checking OS_OBJECT_USE_OBJC and using a newer CocoaPods.



来源:https://stackoverflow.com/questions/27267865/strong-dispatch-queue-t-in-cocoapods-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!