gpt4 book ai didi

swift - Swift 中的反射(内省(introspection))

转载 作者:行者123 更新时间:2023-11-28 09:21:21 27 4
gpt4 key购买 nike

<分区>

是否可以在运行时确定Any对象的类?并将类转换为人类可读的字符串?

是否可以获取该对象支持的方法列表?

class Foo {
let desc = "Foo"
}

class Bar {
let desc = "Bar"
}

var x:Any = Foo()

var className = "___WHAT COMES HERE_____"
println("x is class=\(className)")
// also print list of methods on x if possible

x = Bar()
className = "___WHAT COMES HERE_____"
println("x is class=\(className)")

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