If you check the headers:
public mutating func append(newElement: Element)
public mutating func appendContentsOf<C : CollectionType where C.Generator.Element == Element>(newElements: C)
Note the difference in type specifiers. While it append
allows you to add something that is Element
, that is, includes footers, it appendContentsOf
forces you to use an array with exactly the same type of element (subclasses are not allowed).
He will work with:
let subclassItems = [Base](count: 3, repeatedValue: SubclassOfBase())
, , , (, where
, ).
:
subclassItems.forEach {items.append($0)}
( Array
, CollectionType
)
extension Array {
public mutating func appendContentsOf(newElements: [Element]) {
newElements.forEach {
self.append($0)
}
}
}
items.appendContentsOf(subclassItems as [Base])