禁用 Xcode 中特定行中的特定警告

发布于 2024-09-07 22:33:32 字数 389 浏览 2 评论 0原文

我正在针对 Base 4.0 SDK 编写 iPhone 应用程序,但我的目标是 OS 3.1.3,以便 OS 3 用户可以使用该应用程序。

我调用:

[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];

在 iOS 4.0 中已弃用。我知道这一点,并且如果我们在 iOS 4.0 或更高版本下运行,则已采取措施调用较新的“withAnimation”版本。

但是,我收到一条警告,指出我正在调用已弃用的 SDK。

我想在这个特定的地方禁用这个特定的警告。我想要所有其他警告(包括其他位置的相同已弃用警告)

这可以在 Xcode 中完成吗?

I'm writing an iPhone app against the Base 4.0 SDK, but I'm targeting OS 3.1.3 so OS 3 users can use the app.

I call:

[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];

which is deprecated in iOS 4.0. I'm aware of this, and have measures in place to call the newer "withAnimation" version if we are running under iOS 4.0 or greater.

However, I'm getting a warning that I'm calling a deprecated SDK.

I'd like to disable this specific warning in this specific place. I want all other warnings (including the same deprecated warning in other locations)

Can this be accomplished in Xcode?

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

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

发布评论

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

评论(4

不必了 2024-09-14 22:33:32

对于 CLANG,这是有效的:

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
  // Here I like to leave a comment to my future self to explain why I need this deprecated call
  NSString *myUDID = [[UIDevice currentDevice] uniqueIdentifier];
#pragma clang diagnostic pop

您可以在方法中使用它,这使您可以非常具体地了解导致您想要忽略的警告的行。

For CLANG, this works:

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
  // Here I like to leave a comment to my future self to explain why I need this deprecated call
  NSString *myUDID = [[UIDevice currentDevice] uniqueIdentifier];
#pragma clang diagnostic pop

You can use it inside a method, which allows you to be very specific about the line that causes the warning you want to have ignored.

感情洁癖 2024-09-14 22:33:32

您也许可以使用 GCC 编译指示。这应该禁用所包含函数的已弃用警告。

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated"
-(void)foo{
    // As Georg Fritzsche notes below, the pragmas only work outside of functions
    [[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
}
#pragma GCC diagnostic pop

我不知道这是否适用于 Clang,但它应该适用于 GCC。

基本上,它保存警告/错误的状态,禁用已弃用的警告,编译函数,然后恢复诊断的状态。

You might be able to use GCC pragmas. This should disable the deprecated warning for the enclosed function.

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated"
-(void)foo{
    // As Georg Fritzsche notes below, the pragmas only work outside of functions
    [[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
}
#pragma GCC diagnostic pop

I don't know if this will work with Clang, but it should work with GCC.

Basically, it saves the state of the warnings/errors, disables the deprecated warning, compiles the function, then restores the state of the diagnostics.

闻呓 2024-09-14 22:33:32

您可以使用

UIApplication *app = [UIApplication sharedApplication];
SEL sel = @selector(setStatusBarHidden:animated:);
NSMethodSignature *sig = [app methodSignatureForSelector:sel];
NSInvocation *inv = [NSInvocation invocationWithMethodSignature:sig];
BOOL b = YES;
[inv setTarget:app];
[inv setSelector:sel];
[inv setArgument:&b atIndex:2];
[inv setArgument:&b atIndex:3];
[inv invoke];

欺负

UIApplication *app = [UIApplication sharedApplication];
SEL sel = @selector(setStatusBarHidden:animated:);
IMP imp = [app methodForSelector:sel];
imp(app, sel, YES, YES);

You can use NSInvocation to get around the warnings independent of the compiler used:

UIApplication *app = [UIApplication sharedApplication];
SEL sel = @selector(setStatusBarHidden:animated:);
NSMethodSignature *sig = [app methodSignatureForSelector:sel];
NSInvocation *inv = [NSInvocation invocationWithMethodSignature:sig];
BOOL b = YES;
[inv setTarget:app];
[inv setSelector:sel];
[inv setArgument:&b atIndex:2];
[inv setArgument:&b atIndex:3];
[inv invoke];

Or in a less error-tolerant way:

UIApplication *app = [UIApplication sharedApplication];
SEL sel = @selector(setStatusBarHidden:animated:);
IMP imp = [app methodForSelector:sel];
imp(app, sel, YES, YES);
清醇 2024-09-14 22:33:32

您可以像这样执行它以立即克服警告

#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
(void) methodUsingDeprecatedStuff { //use deprecated stuff }

,或者

只需在每次使用已弃用的内容之前粘贴此行以避免警告

#pragma GCC 诊断警告“-Wdeprecated-declarations”

这将删除警告。

希望它能帮助你。

you can perform it like this to overcome the warnings at once

#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
(void) methodUsingDeprecatedStuff { //use deprecated stuff }

or

Just paste this line before using your deprecated stuffs every time to avoid warnings

#pragma GCC diagnostic warning "-Wdeprecated-declarations"

this will remove the warnings.

Hope it will help you.

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