Swift 支持反射吗? [英] Does Swift support reflection?
本文介绍了Swift 支持反射吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Swift 支持反射吗?例如Swift 对象是否有类似 valueForKeyPath:
和 setValue:forKeyPath:
的东西?
Does Swift support reflection? e.g. is there something like valueForKeyPath:
and setValue:forKeyPath:
for Swift objects?
实际上它甚至有一个动态类型系统,比如 Objective-C 中的 obj.class
吗?
Actually does it even have a dynamic type system, something like obj.class
in Objective-C?
推荐答案
看起来有些反射支持开始了:
Looks like there's the start of some reflection support:
class Fruit {
var name="Apple"
}
reflect(Fruit()).count // 1
reflect(Fruit())[0].0 // "name"
reflect(Fruit())[0].1.summary // "Apple"
来自 mchambers 的要点,这里:https://gist.github.com/mchambers/fb9da554898dae3e54f2
From mchambers gist, here: https://gist.github.com/mchambers/fb9da554898dae3e54f2
这篇关于Swift 支持反射吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文