Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apple Mach-O Linker Warning in Xcode8 beta6, swift3.0. Still exists in Xcode8 GM [duplicate]

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

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.

like image 705
jherg Avatar asked Sep 23 '16 16:09

jherg


5 Answers

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
   }
}

From the apple docs:

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

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

like image 187
juanjo Avatar answered Nov 03 '22 00:11

juanjo


In my case, the reason was having computed type property in an extension:

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

Not sure what the exact reason behind this is, but to get rid of the warning I had to convert the computed type property (class var) to a type method (class func):

extension NSParagraphStyle {
    class func defaultStyle() -> NSParagraphStyle {
        return ...
    }
}
like image 22
Hejazi Avatar answered Nov 02 '22 23:11

Hejazi


This warning appeared in my project after adding a framework that used Objective-C in my application that otherwise used Swift 3 entirely.

By declaring all static functions and static variables in all extensions as @nonobjc this warning went away.

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)
}
like image 35
Groot Avatar answered Nov 02 '22 23:11

Groot


Google Analytics pod

In Build Settings -> Other Linker Flags if you have the -ObjC on -l"GoogleAnalytics" flag this warning will appear. I don`t know why or how to resolve, but can be your problem too.

like image 45
Renato Ioshida Avatar answered Nov 03 '22 00:11

Renato Ioshida


In my case it was a class variable.

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

Adding @nonobjc helped.

like image 34
Bogdan Avatar answered Nov 03 '22 00:11

Bogdan