我新手swift IOS ..我用这台翠鸟从网址上获取图像..
这是原始代码..
let kingfisherSource = [KingfisherSource(urlString:"https://images.unsplash.com/photo-1432679963831-2dab49187847?w=1080")!, KingfisherSource(urlString: "https://images.unsplash.com/photo-1447746249824-4be4e1b76d66?w=1080")!, KingfisherSource(urlString: "https://images.unsplash.com/photo-1463595373836-6e0b0a8ee322?w=1080")!]
我有动态数据..例如,网址可以是一个,也可以是两个或多个..
我怎样才能获得像这样的代码
let kingfisherSource = [KingfisherSource(urlString:"url[0]")!, KingfisherSource(urlString: "url[1]")!, KingfisherSource(urlString: "url[2]")!]
这是我的代码..但我不知道如上所述......
for index in 0 ..< self.orderAttemptImageArray.count {
print(orderAttemptImageArray[index].mUrl!)
var kingfisherSource = [KingfisherSource(urlString: "\(orderAttemptImageArray[index].mUrl!)")!]
}
请帮帮我..
答案 0 :(得分:1)
首先初始化一个KingfisherSource类型的数组
var items = [KingfisherSource]()
然后做你之前做过的事情&amp;将每个kingfisherSource对象附加到items数组中。
for index in 0 ..< self.orderAttemptImageArray.count{
var kingfisherSource = KingfisherSource(urlString: "\(orderAttemptImageArray[index].mUrl!)")! as! KingfisherSource
items.append(kingfisherSource)
}
希望它有所帮助。