Objective-C class property in category causes warning

1k Views Asked by At

In Xcode 8.3.2 and Objective-C, if you have a class property in a category, it sometimes causes a warning. How can I get rid of it?

The warning is

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.

The class property would look something like this:

 @interface NSObject (Thingie)

 @property (class, readonly, strong) id thingie;

 @end

And the implementation

@implementation NSObject (Thingie)

+ (id)thingie {
  return nil; // doesn't matter for this
}

@end
1

There are 1 best solutions below

2
On

I recently ran into this issue. It happens when you use a newer version of Xcode (not sure what the version cutoff is) and your project defines an Objective-C category that declares one or more class properties and you also link to a library that was built with a version of Xcode that didn't support class properties.

I was able to eliminate the warning by translating my class properties into "getter' methods.

In your case, update your .h file to:

@interface NSObject (Thingie)

+ (id)thingie;

@end

That covers the class and readonly attributes of the property. And the strong attribute is essentially superfluous in a read-only property.

This conversion has no effect on the usage. You can still do:

id aThingie = someObject.thingie;