Search code examples
iosobjective-cxcodecompiler-errorsgameplay-kit

Xcode error: Semantic Issue, Property 'className' not found on object type 'GKEntity *'


Recently I started getting this error from Xcode:

Error Screenshot

This 'className' property belongs to NSObject. Here is the official documentation.

Why is this happening and how do I solve this (without avoiding using this property)?


The strange thing is that the exact same code worked just fine a few days ago on both the macOS AND the iOS target. Then it started showing this error AFTER the build successfully completed (i could run the project just fine), but now the iOS target won't even build...

I tried (1) purging my derivedData folder many times, (4) doing clean checkouts, (3) restarting Xcode, and (2) restarting the system, all of that in the correct order, but no success...

I'm using Xcode Version 8.2.1 on macOS 10.12.3 and my deployment targets are 10.2 for iOS and 10.12 for macOS.


Solution

  • As pointed out by @JamesP in a comment above the className property is clearly documented to exist only on macOS 10.0+, and not on iOS, which i failed to notice...

    This means that my problem came from the fact that i changed my implementation's target settings from macOS only to macOS and iOS during development.

    Because i'm using Objective-C i ended up replacing entity.className with

    NSStringFromClass([entity class])
    

    The answer from @Russel shows how to solve this in Swift.