[英]Xcode error: Semantic Issue, Property 'className' not found on object type 'GKEntity *'
Recently I started getting this error from Xcode:最近我开始从 Xcode 收到这个错误:
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.