我是Swift的新手,正在尝试一些教程来学习并在Swift上磨练我的知识。我偶然发现了这个我不明白的代码中的错误。如果你们中的任何人有想法,请在此解释最新情况。参数类型'Int'不符合期望的类型'NSCoding&NSCopying&NSObjectProtocol'
let textChoices = [
ORKTextChoice(text: "Create a ResearchKit app", value:0),
ORKTextChoice(text: "Seek the Holy grail", value:1),
ORKTextChoice(text: "Find a shrubbery", value:2)
]
我决心通过建议由Xcode中提供的错误,现在我的代码看起来像
let textChoices = [
ORKTextChoice(text: "Create a ResearchKit app", value:0 as NSCoding & NSCopying & NSObjectProtocol),
ORKTextChoice(text: "Seek the Holy grail", value:1 as NSCoding & NSCopying & NSObjectProtocol),
ORKTextChoice(text: "Find a shrubbery", value:2 as NSCoding & NSCopying & NSObjectProtocol)
]
还有另一种解决方案,我从answer了。虽然它有效,但我仍然不清楚问题和解决方案。我错过了什么概念。