我想将所有对象追加到一行中.我有一些像这样的对象:
let abaddon = Hero(name: "abaddon") let ember = Hero(name: "ember") let gondar = Hero(name: "gondar") let kael = Hero(name: "kael") let kunkka = Hero(name: "kunkka") let layana = Hero(name: "layana") let lucifer = Hero(name: "lucifer") let omni = Hero(name: "omni") let soul = Hero(name: "soul") let wind = Hero(name: "wind")
英雄对象是这样的:
class Hero { var name: String! var image: UIImage? { return UIImage(named: "\(name)")! } required init(name: String) { self.name = name } }
我想把它们放到这个数组中:var heroes = [Hero]()
但我看到追加只能每次放一个物体.
heroes.append(abaddon)
如何在单行中追加多个对象,如下所示:
heroes.append([abaddon,ember,gondar])
任何帮助将不胜感激,谢谢.
如果要附加多个对象,可以将它们自己包装到数组中并使用appendContentsOf.
heroes.appendContentsOf([abaddon,gondor])