简体   繁体   English

Xcode 错误:语义问题,在对象类型“GKEntity *”上找不到属性“className”

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

Recently I started getting this error from Xcode:最近我开始从 Xcode 收到这个错误:

Error Screenshot错误截图

This 'className' property belongs to NSObject.这个 'className' 属性属于 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.奇怪的是,几天前完全相同的代码在 macOS 和 iOS 目标上运行良好。 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...然后它在构建成功完成后开始显示此错误(我可以很好地运行该项目),但现在 iOS 目标甚至不会构建......

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...我尝试(1)多次清除我的derivedData文件夹,(4)进行干净的结帐,(3)重新启动Xcode,以及(2)重新启动系统,所有这些都以正确的顺序进行,但没有成功......

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.我在macOS 10.12.3上使用Xcode 版本 8.2.1 ,我的部署目标是 iOS 10.2 和 macOS 10.12。

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确实找到了一个解决方案, Get class name of object as string in Swift

String(describing: type(of: self))

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...正如@JamesP 在上面的评论中指出的那样,className 属性被明确记录为仅存在于 macOS 10.0+ 上,而不存在于 iOS 上,我没有注意到...

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.这意味着我的问题来自于我在开发过程中将实现的目标设置从仅 macOS 更改为 macOS 和 iOS。

Because i'm using Objective-C i ended up replacing entity.className with因为我使用的是 Objective-C,所以我最终将entity.className替换为

NSStringFromClass([entity class])

The answer from @Russel shows how to solve this in Swift. @Russel 的答案展示了如何在 Swift 中解决这个问题。

A neat little extension should do the trick.一个整洁的小扩展应该可以解决问题。

public extension NSObject {

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在xcode 6上出现语义问题“在FeedViewController类型的对象上找不到属性tabBarItem”,但在xcode 5.1.1上运行正常 - Getting semantic issue “property tabBarItem not found on object of type FeedViewController” on xcode 6, but on xcode 5.1.1 its working fine 构建失败,语义问题属性'expiredPermissions'在'FBSDKAccessToken *'类型的对象上找不到 - Build Failed with Semantic Issue Property 'expiredPermissions' not found on object of type 'FBSDKAccessToken *' Xcode CodeSense错误-在类型的对象上找不到属性,但项目可以编译 - Xcode CodeSense error - Property not found on object of type, but project compiles 在对象上找不到属性类型(自定义)xcode - property not found on object Type (custom) xcode 在Xcode 9.4 iOS类型的对象上找不到属性“ ...” - Property '…' not found on object of type '…' xcode 9.4 ios 在 Xcode 中运行 Ionic 3 应用程序时出错“在“AppDelegate”类型的 object 上找不到属性“isPairedWatchExist” - Error on running a Ionic 3 App in Xcode “Property 'isPairedWatchExist' not found on object of type 'AppDelegate” 错误“在类型为“ MyAnnotation”的对象上找不到属性“标题”” - Error “ Property 'title' not found on object of type 'MyAnnotation' ” 在类型为“ ...”的对象上找不到错误属性“ ...” - I get the error Property '…' not found on object of type '…' 错误:在类型为“ id”的对象上找不到属性“数据” - Error: property 'data' not found on object of type 'id' 错误:在“ UIView *”类型的对象上找不到属性“ frame” - error: property 'frame' not found on object of type 'UIView *'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM