Swift支持反思吗? [英] Does Swift support reflection?

查看:104
本文介绍了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 gist,这里:
https:// gist .github.com / mchambers / fb9da554898dae3e54f2

From mchambers gist, here: https://gist.github.com/mchambers/fb9da554898dae3e54f2

这篇关于Swift支持反思吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆