“__强”仅适用于 Objective-C 对象或块指针类型;这里输入的是 XXX”警告

发布于 2025-01-08 20:55:39 字数 1276 浏览 0 评论 0原文

我收到很多类型的警告:

'__strong'仅适用于objective-c对象或块指针类型;此处输入的是...

警告指向框架标头。例如 NSNotification、NSURL、NSIndexset 等。

它们是什么以及如何修复它?

注 1:我使用 ARC

注 2:该应用程序似乎可以工作

编辑 1:警告似乎源自我的 pch 文件。这是:

//
// Prefix header for all source files of the 'myapp' target in the 'myapp' project
//

#import <Availability.h>

#ifndef __IPHONE_5_0
     #warning "This project uses features only available in iOS SDK 5.0 and later."
#endif

#ifdef __OBJC__
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
#endif

编辑2: 警告示例: NSString.h 中的警告指向:

/* Methods to convert NSString to a NULL-terminated cString using the specified encoding.     Note, these are the "new" cString methods, and are not deprecated like the older cString     methods which do not take encoding arguments.
*/
- (__strong const char *)cStringUsingEncoding:(NSStringEncoding)encoding; //"Autoreleased"; NULL return if encoding conversion not possible; for performance reasons, lifetime of this should not be considered longer than the lifetime of the receiving string (if the receiver string is freed, this might go invalid then, before the end of the autorelease scope)

i get many warnings of type:

'__strong' only applies to objective-c object or block pointer types; type here is...

the warnings are pointing to framework headers. e.g NSNotification, NSURL, NSIndexset etc..

what are they and how can i repair it?

note 1: i use ARC

note 2: the app seems to work

edit 1: the warnings seems to originate from my pch file. which is:

//
// Prefix header for all source files of the 'myapp' target in the 'myapp' project
//

#import <Availability.h>

#ifndef __IPHONE_5_0
     #warning "This project uses features only available in iOS SDK 5.0 and later."
#endif

#ifdef __OBJC__
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
#endif

edit 2:
example of warning:
warning in NSString.h point to:

/* Methods to convert NSString to a NULL-terminated cString using the specified encoding.     Note, these are the "new" cString methods, and are not deprecated like the older cString     methods which do not take encoding arguments.
*/
- (__strong const char *)cStringUsingEncoding:(NSStringEncoding)encoding; //"Autoreleased"; NULL return if encoding conversion not possible; for performance reasons, lifetime of this should not be considered longer than the lifetime of the receiving string (if the receiver string is freed, this might go invalid then, before the end of the autorelease scope)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

静谧 2025-01-15 20:55:39

阿米尔的答案对我不起作用,但它让我找到了类似的解决方案:确保项目设置或目标设置中的 FRAMEWORK_SEARCH_PATHS 中也没有框架路径。我的有一个条目看起来像这样:

$(DEVELOPER_DIR)/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks

症状是,如果我命令单击我的 prefix.ch 中的 Foundation/Foundation.h,然后在页面中右键单击 -> 在 Finder 中显示,它位于 iPhoneOS.platform 中。但是对 Availability.h 进行同样的操作将我带到 iPhoneSimulator.platform。

因此,包含来自每个平台的一些文件似乎导致了 __strong 警告以及一些链接错误,其中显示缺少架构 i386,因此我失去了在 iOS 模拟器中运行的能力。

这个错误让我<需要 2 天 才能解决,因为该路径已在我的目标设置中存在了数月,但并未造成问题。有关 Xcode 6 的一些信息揭示了这一点,但不是立即出现的,它只是在本周早些时候我升级 Google AdMob SDK 时自发发生的,并且可能触发了缓存重建。

最阴险的事情是,尝试编译我的项目的备份也因同样的错误而失败。

让我们暂时理解这一点,想象一下厄运即将来临的感觉。

那时我开始怀疑硬件故障或病毒,但幸运的是......

该错误是在 Xcode 级别,而不是项目级别。这让我相信它与 SHARED_PRECOMPS_DIR、CACHE_ROOT 或可能 /var/folders 有关,但那时我出于绝望而升级到 Yosemite,无法将我的硬盘驱动器与我的 Time Machine 备份(其中有 Mavericks)进行比较。事后看来,这就是我搞砸的地方。这意味着我必须尝试其他十几种涉及 PCH 和其他缓存的潜在解决方案,但没有一个有效。也没有删除项目的派生数据目录:

~/Library/Developer/Xcode/DerivedData

(我是根据 这个答案)

另请参阅:

无法在 Xcode 6 中构建 - Apple 框架中的 ARC 问题< /a>

和:

构建错误 - 文件中缺少所需的架构 i386

具体来说:

Sean Roehnelt 的回答

Amir's answer did not work for me, but it led me to a similar solution: make sure you also don't have a Frameworks path in your FRAMEWORK_SEARCH_PATHS in project settings or target settings. Mine had an entry that looked like this:

$(DEVELOPER_DIR)/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks

The symptom was that if I command-clicked Foundation/Foundation.h in my prefix.ch and then right clicked in the page->Show in Finder, it was in iPhoneOS.platform. But doing the same with Availability.h took me to iPhoneSimulator.platform.

So having some files including from each platform seems to have caused the __strong warnings and also some link errors where it said missing architecture i386, so I lost the ability to run inside iOS Simulator.

This bug took me 2 days to solve because that path had been in my target settings for months, but wasn't causing problems. Something about going to Xcode 6 revealed it, but not immediately, it just occurred spontaneously early this week when I was upgrading Google AdMob SDK and perhaps triggered a cache rebuild.

The particularly insidious thing about it was that trying to compile backups of my project also failed with the same error.

Let that sink in for a moment, and imagine the sense of impending doom.

I began to suspect hardware failures or a virus at that point, but luckily..

The bug was at the Xcode level, not the project level. Which leads me to believe it has something to do with SHARED_PRECOMPS_DIR, CACHE_ROOT or possibly /var/folders but by then I had upgraded to Yosemite out of sheer desperation and could not diff my hard drive against my Time Machine backup, which had Mavericks. In hindsight, that's where I blew it. That meant that I had to try a dozen other potential solutions involving PCH and other caches, none of which worked. Neither did deleting the project's derived data directories in:

~/Library/Developer/Xcode/DerivedData

(Which I had done based on this answer)

See also:

Can't Build in Xcode 6 - ARC Issues in Apple Frameworks

and:

Build Error - missing required architecture i386 in file

Specifically:

Sean Roehnelt's answer

装迷糊 2025-01-15 20:55:39

看来我已经解决了。
由于某种原因,我的项目本地文件夹中有一个带有标题的“Framework”文件夹。删除该文件夹,警告就会消失。我不知道该文件夹是如何以及为何创建的。 (我没有创建它)。

it seems i've solved it.
for some reason i had a "Framework" folder with headers in my project local folder. removing that folder and the warnings are gone. i don't know how and why that folder was created. (i did not created it).

Saygoodbye 2025-01-15 20:55:39

这是一个疯狂的猜测:您的项目使用 gcc 吗?如果是,请尝试切换到 clang

This is a wild guess : is your project using gcc ? If it is, try switching to clang

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文