数组初始化调用Array.init(repeating: UIButton(), count: 6)
为啥数组中只有6个按钮,但是是同一个对象。不是应该创建六个不同的对象吗?
Declaration
iOS, macOS, tvOS, watchOS
init(repeating repeatedValue: Array.Element, count: Int)
Parameters
repeatedValue
The element to repeat.
count
The number of times to repeat the value passed in the repeating parameter. count must be zero or greater.
官方文档有提到,一个对象的重复
您这样的创建方法只是标明创建的数组初始化为六个元素,谢谢,请采纳
好长时间没做iOS了
UIButton()返回的仅仅是一个变量名,变量名指向的是堆中的代码实现区!并且重复创建的方法是创建相同的对象与元素,