gpt4 book ai didi

ios - 如何在 Swift 2 中将结构转换为 Anyobject?

转载 作者:IT王子 更新时间:2023-10-29 05:39:31 25 4
gpt4 key购买 nike

我有,

struct S {}

连同,

func y (x: S) -> AnyObject {}

在 Swift 2 中,是否有可能在 y() 中,

return x

我当前的代码:

struct S {let value: Int = 0}
let x = S()
func y(x: S) -> AnyObject {return x}

产生以下错误:

return expression of type 'S' does not conform to type 'AnyObject'

有没有办法缓解这种情况?

最佳答案

Struct 不能符合 AnyObject。它只能符合Any

关于ios - 如何在 Swift 2 中将结构转换为 Anyobject?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33921907/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com