Xcode 8 Objective-C类别警告 [英] Xcode 8 Objective-C category warning

查看:1553
本文介绍了Xcode 8 Objective-C类别警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Xcode 8和Swift 3.0。此错误消息的含义是什么?

I'm using Xcode 8 and Swift 3.0. What does this error message mean?


ld:警告:某些目标文件具有不兼容的Objective-C类别定义。某些类别元数据可能会丢失。所有包含Objective-C类别的文件都应使用相同的编译器构建。

ld: warning: Some object files have incompatible Objective-C category definitions. Some category metadata may be lost. All files containing Objective-C categories should be built using the same compiler.


推荐答案

我也是在 UIColor 扩展中有这个问题,我的应用程序完全由swift制作,除了一些使用Objective-c的框架,所以我在声明 var as @nonobjc

I also had this issue in a UIColor extension, my app is entirely made with swift except for some frameworks that use Objective-c so I have no problem in declaring the var as @nonobjc:

extension UIColor {
   @nonobjc static var lol: UIColor {
      return UIColor.red
   }
}

来自apple docs:

From the apple docs:


nonobjc属性告诉编译器使声明不可用在Objective-C代码中......

The nonobjc attribute tells the compiler to make the declaration unavailable in Objective-C code...

由于此代码对Objective-C不可用,警告消失。

Since this code is unavailable to Objective-C the warning disappears.

这篇关于Xcode 8 Objective-C类别警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆