星空网 > 软件开发 > 操作系统

(转)怎么去掉Xcode工程中的某种类型的警告 Implicit conversion loses integer precision: NSInteger (aka long) to int32

问题描述 
在我们的项目中,通常使用了大量的第三方代码,这些代码可能很复杂,我们不敢改动他们,可是作者已经停止更新了,当sdk升级或者是编译器升级后,这些遗留的代码可能会出现许许多多的警告,那么我们有没有办法去掉这些烦人的警告,不然一个工程几百个警告,你看着怎么都不爽吧.我们怎么去掉警告呢
 
1.最直接,最一劳永逸,最安全的方式,直接找到警告的那段代码,改为不警告.这个方式,最安全.
可是它有一个问题,就是,当我们很多文件都有这种类型的警告的时候,我们就需要改动很多很多的源码了, 对于不是我们写的源码,有可能随时会更新的,我们这种方式,显然就不太可取了.
 
2.使用编译器提供的宏来操作,这个方式在我们的工程中会大量的看到
#pragma clang diagnostic push
#pragma clang diagnostic ignored"-Wdeprecated-declarations"
               //写在这个中间的代码,都不会被编译器提示-Wdeprecated-declarations类型的警告
dispatch_queue_tcurrentQueue =dispatch_get_current_queue();
#pragma clang diagnostic pop
 
这种方式的问题,同第一个差不多,也是要修改源代码的实现的,对于第三方,我们肯定是不想改动它的,尤其是一些更新很频繁的第三方,一般警告出现后不久,作者就更新了,我们在此做这样的操作,就显得浪费了.并且在 添加arm64支持的时候,一下出现几百个某种类型的警告,改起来也是相当费时费力的啊!
比如我们的工程,打开了arm64,然后编译
(转)怎么去掉Xcode工程中的某种类型的警告 Implicit conversion loses integer precision: NSInteger (aka long) to int32images/loading.gif' data-original="http://img.blog.csdn.net/20141217174437072" />
 
 
3.关闭某一个指定文件的某种指定类型的警告
这里,拿一个具体工程来说吧.比如我们工程里有一个文件  PresencePacket
(转)怎么去掉Xcode工程中的某种类型的警告 Implicit conversion loses integer precision: NSInteger (aka long) to int32
 
其实关闭某个指定文件的某种类型的警告很简单,就如同我们以前给某一个文件添加 ARC支持或者不支持的时候那样 添加 忽略/显示 某种类型警告
(转)怎么去掉Xcode工程中的某种类型的警告 Implicit conversion loses integer precision: NSInteger (aka long) to int32
双击 文件, 在其中添加  -Wno-shorten-64-to-32  (这个关键在就是让编译器忽略 Implicit conversion loses integer precision: 'NSInteger' (aka 'long') to 'int32_t' (aka 'int') 警告)
(转)怎么去掉Xcode工程中的某种类型的警告 Implicit conversion loses integer precision: NSInteger (aka long) to int32
添加完成后,再编译,那么PresencePacket文件中的  Implicit conversion loses integer precision: 'NSInteger' (aka 'long') to 'int32_t' (aka 'int’) 警告就没有了,是不是很简单,很方便.
 
 
 
这种方式,已经是大大的减少了工作量了,只需要在指定的文件的编译中添加 -Wno-shorten-64-to-32就可以了.那么有没有什么方式可以让编译器忽略整个工程中的 指定类型的警告呢?
 
4.关闭工程中指定 类型的警告
这个最简单了, 工程的target有一个 Other Warning Flags 
(转)怎么去掉Xcode工程中的某种类型的警告 Implicit conversion loses integer precision: NSInteger (aka long) to int32
在其中添加 -Wno-shorten-64-to-32
(转)怎么去掉Xcode工程中的某种类型的警告 Implicit conversion loses integer precision: NSInteger (aka long) to int32
再重新编译,哈哈,整个文件中的  Implicit conversion loses integer precision: 'NSInteger' (aka 'long') to 'int32_t' (aka 'int’) 警告全部消失了!!!!
 
 
5.大家可能很疑惑,上面的-Wno-shorten-64-to-32 是怎么来的,我怎么知道   Implicit conversion loses integer precision: 'NSInteger' (aka 'long') to 'int32_t' (aka 'int’) 警告 就是 -Wno-shorten-64-to-32类型呢?这里,其实不需要记忆的,当工程中有这种类型警告的时候
 
在警告窗口,某个警告上,我们右击,显示出右键菜单,选择其中的 Reveal in Log
(转)怎么去掉Xcode工程中的某种类型的警告 Implicit conversion loses integer precision: NSInteger (aka long) to int32
 
则会显示 
(转)怎么去掉Xcode工程中的某种类型的警告 Implicit conversion loses integer precision: NSInteger (aka long) to int32
注意到其中 [-Wshorten-64-to-32],在这个括号中的就是 这种警告的类型   -W是前缀,这个前缀表示的是 打开这种类型的警告 如果我们是要关闭某种类型的警告的话, 要将 -W换成 -Wno-  
这样就得到了  -Wno-shorten-64-to-32了.
 
 
 
后记:
对于我们使用cocoapod引入的第三方,我们可以在podfile文件中 增加一句  inhibit_all_warnings! 来要pod的工程不显示任何警告,
例如
link_with 'SecondHouseBrokerAPP','SecondHouseBrokerCOM'
platform :ios,'6.0'
inhibit_all_warnings!


pod 'CocoaAsyncSocket'
pod 'Reachability'
pod 'ProtobufObjC'
pod 'SDWebImage'
pod 'FMDB'
pod 'GPUImage'
pod 'CXPhotoBrowser'
pod 'CocoaLumberjack'
 
还有就是,上面的方法也适合其它类型的警告!!!

 



原标题:(转)怎么去掉Xcode工程中的某种类型的警告 Implicit conversion loses integer precision: NSInteger (aka long) to int32

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

选品无力,引流无效?一招即可KO!:https://www.ikjzd.com/articles/129404
亚马逊英国因出售这款产品,遭外界强烈抨击:https://www.ikjzd.com/articles/129427
你中枪了没?产品排名低,店铺销量差,居然是因为没读懂亚马逊后台报告?:https://www.ikjzd.com/articles/129428
如何推广我们的亚马逊联盟网站?:https://www.ikjzd.com/articles/129429
亚马逊全球产品认证大全,你了解多少?:https://www.ikjzd.com/articles/129436
2020年互联网创业、亚马逊测评为什么能独占鳌头?:https://www.ikjzd.com/articles/129437
珠海市图书馆官网入口:https://www.vstour.cn/a/335174.html
珠海图书馆几点开门几点关门?附营业时间:https://www.vstour.cn/a/335175.html
相关文章
我的浏览记录
最新相关资讯
跨境电商服务平台 | 深圳旅行社 | 东南亚物流