ZanYzer
ZanYzer

Reputation: 45

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.

Upvotes: 0

Views: 1484

Answers (3)

leerie simpson
leerie simpson

Reputation: 186

A neat little extension should do the trick.

public extension NSObject {

    var nameOfClass: String {
        String(describing: type(of: self))
    }
}

Upvotes: 0

ZanYzer
ZanYzer

Reputation: 45

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.

Upvotes: 2

Russell
Russell

Reputation: 5554

I can't find any explanation of why this property has been removed, but it does appear to be!

I did find a solution, Get class name of object as string in Swift

String(describing: type(of: self))

Upvotes: 2

Related Questions