Swift 将多个 IBOutlets 放入一个数组中 [英] Swift put multiple IBOutlets in an Array
本文介绍了Swift 将多个 IBOutlets 放入一个数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用 ctrl + drag
但我不喜欢完全相同的行 9 次(DRY)
But i don't like to have the exact same line 9 times (DRY)
如何将这些 IBOutlets 放入数组中?
How do i put these IBOutlets in an Array?
推荐答案
你可以像这样在 Swift 中定义一个通用的 outlet 集合:
you can define a generic outlet collection in Swift like this:
@IBOutlet var collectionOfViews: Array<UIView>? // = [UIView]?
或例如UIButton
对象:
@IBOutlet var collectionOfButtons: Array<UIButton>? // = [UIButton]?
<小时>
您可以在 Outlet Collections 组下找到您的收藏,就像通常在 File's Owner 中一样:
you can find your collections under the Outlet Collections group as usually are in the File's Owner:
它会在连接 5 个随机按钮后显示在我的控制台上:
it would look on my console after connecting 5 random buttons:
这篇关于Swift 将多个 IBOutlets 放入一个数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文