我试图用一些AnyObject类型的属性来定义一个协议,然后在符合协议的类中,属性类型是SomeClass.但是这会返回编译器错误.我不得不将类中的类型更改为AnyObject.如何在协议定义中使用超类并将子类用作属性类型?
谢谢!
protocol TestProtocol {
var prop: [AnyObject] {get}
}
class Test: TestProtocol {
var prop = [SomeClass]() //compiler error
var prop = [AnyObject]() //this will work
}
Run Code Online (Sandbox Code Playgroud) 我已经被这个问题困扰了好几天了。如果有人能给我指明方向,我真的很感激。
\n突然之间,我无法在模拟器上构建手表应用程序 - 但我仍然可以在设备上构建。它显示如下错误。它看起来像目标架构问题,但构建设置架构设置为 $(ARCHS_STANDARD)。
\n显示错误消息后,模拟器有未完成安装的应用程序。点击它会触发另一个对话框:开发人员需要更新此应用程序才能在此版本的 watchOS 上运行。
\nDetails\n\n\xe2\x80\x9cxxx\xe2\x80\x9d Needs To Be Updated\nDomain: IXUserPresentableErrorDomain\nCode: 4\nFailure Reason: This app needs to be updated by the developer to work on this version of watchOS.\nRecovery Suggestion: Failed to find matching arch for input file: /Users/xxx/Library/Developer/CoreSimulator/Devices/D5BAD233-3780-483A-BD6C-880255002917/data/Library/Caches/com.apple.mobile.installd.staging/temp.V1pK3n/extracted/Watch.app/PlugIns/Watch Extension.appex/Watch Extension\n--\nFailed to find matching arch for input file: /Users/xxx/Library/Developer/CoreSimulator/Devices/D5BAD233-3780-483A-BD6C-880255002917/data/Library/Caches/com.apple.mobile.installd.staging/temp.V1pK3n/extracted/Watch.app/PlugIns/Watch Extension.appex/Watch Extension\nDomain: MIInstallerErrorDomain\nCode: 15\nUser Info: {\n FunctionName = MIMachOFileMatchesMyArchitecture;\n LegacyErrorString = IncorrectArchitecture;\n SourceFileLine = 51;\n}\n\nSystem Information\n\nmacOS Version 11.0.1 (Build 20B29)\nXcode 12.2 (17535) (Build 12B45b)\nTimestamp: 2020-11-30T15:27:57+11:00\n\n …
Run Code Online (Sandbox Code Playgroud)