Xcode 8 Objective-C Category Warning

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

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

+53
ios objective-c xcode swift xcode8
Sep 23 '16 at 16:58
source share
8 answers

I also had this problem in the UIColor extension, my application is completely built with a fast one, with the exception of some frameworks that use Objective-c, so I have no problem declaring var like @nonobjc :

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

From apple docs:

The nonobjc attribute tells the compiler that the declaration is not available in Objective-c code ...

Since this code is not available for Objective-c, the warning disappears.

+36
Nov 25 '16 at 20:10
source share

In my case, the reason was to calculate the type property in the extension:

 extension NSParagraphStyle { class var defaultStyle: NSParagraphStyle { return ... } } 

I don’t know what the specific reason is, but in order to get rid of the warning, I had to convert the property of the computed type ( class var ) to a method of type ( class func ):

 extension NSParagraphStyle { class func defaultStyle() -> NSParagraphStyle { return ... } } 
+18
Oct 11 '16 at 10:37
source share

This warning appeared in my project after adding a framework that used Objective-C in my application, which otherwise made full use of Swift 3.

Having declared all static functions and static variables in all extensions as @nonobjc , this warning has disappeared.

for example

 extension Notification.Name { @nonobjc static let MyNotificationName = Notification.Name("NNSongFavoriteStatusDidChangeNotification") } 

or

 extension UIColor { @nonobjc static let superGiantRed = UIColor(red: 180.0/255.0, green: 40.0/255.0, blue: 27.0/255.0, alpha: 1.0) } 
+8
Feb 02 '17 at 19:45
source share

Google analytics pod

In Build Settings β†’ Other linker flags , if you have the -ObjC flag on -l "GoogleAnalytics" , this warning will appear. I do not know why and how to resolve, but it may be your problem.

+7
Nov 08 '16 at 18:44
source share

In my case, it was a class variable.

 public extension NSObject { public class var nameOfClass: String{ return NSStringFromClass(self).components(separatedBy: ".").last! } 

Added support for @nonobjc.

+4
Feb 06 '17 at 14:23
source share

For me, the problem was that I used a third-party structure from a provider created using Xcode 7 in my Swift 3 application built with Xcode 8. Since the framework was compiled binary, the only option I had was to ask my provider for a new framework built with the latest version of Xcode.

+3
Oct 14 '16 at 16:15
source share

I managed to solve my problem when I changed the var class to the func class :

Was:

 class var applicationVersionNumber: String { if let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String { return version } return "Version Number Not Available" } 

It became:

 class func applicationVersionNumber() -> String { if let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String { return version } return "Version Number Not Available" } 

Source: https://forums.developer.apple.com/message/146579#146579

+1
Jul 17 '17 at 14:17
source share

Instead of marking each element as @nonobjc individually, you can instead mark the entire extension as @nonobjc :

 @nonobjc extension UIStoryboard { static let main = UIStoryboard(name: "Main", bundle: nil) static let welcome = UIStoryboard(name: "Main", bundle: nil) } 
0
Jul 06 '17 at 14:45
source share



All Articles