是否存在等效的“评估"?功能快速,就像在Matlab中一样?

编程入门 行业动态 更新时间:2024-10-24 01:56:45
本文介绍了是否存在等效的“评估"?功能快速,就像在Matlab中一样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如果没有,如何循环遍历IBOutlets(如temp1,temp2,temp3)并按顺序访问属性?

If not, how can I loop through IBOutlets (like temp1, temp2, temp3) and chance a property sequentially?

在matlab中,我将连接一个字符串并使用eval.

In matlab, I would concatenate a string and use eval.

for k = 1:3 eval(["temp",num2str(k)]); end

我是Swift的新手,并且想通过IBOutlets做到这一点.像

I'm new to Swift, and want to do this with IBOutlets. Something like,

for(var k = 0, ++k, k==4) { eval(["self.temp",String(k),".backgroundcolor"]); end

我知道eval函数是Matlab格式的,但是我只是在表达我想做的事情.

I know the eval function is in Matlab format, but I'm just expressing what I'd like to have done.

推荐答案

Swift是一种静态类型语言,因此无法在Matlab中实现"eval"之类的东西.您可以通过以下代码达到相同的行为:

Swift is a static type language, so that it's impossible to implement something like "eval" in Matlab. You can reach same behaviour with this code:

@IBOutlet var labels: [UILabel]! override func viewDidLoad() { super.viewDidLoad() for label in labels { label.backgroundColor = UIColor.redColor() } }

尽管可能可以使用运行时进行一些魔术操作,但是连接同一插座集合中的所有组件是最简单的方法.

Although probably it is possible to do some magic using the runtime, connecting all the components in the same outlet collection is the easiest way.

更多推荐

是否存在等效的“评估"?功能快速,就像在Matlab中一样?

本文发布于:2023-07-16 23:03:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1126855.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:就像   是否存在   快速   功能   Matlab

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!