gpt4 book ai didi

arrays - 如何将动态数据快速获取到数组 KingFisher

转载 作者:行者123 更新时间:2023-11-28 15:55:58 24 4
gpt4 key购买 nike

我是 swift IOS 新手 .. 我用这个 kingfisher 从 url 获取图像 ..

这是原始代码..

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")!]

我有动态数据.. 可能 url 可以是一个,也可以是两个或多个 ..

我怎样才能得到这样的代码

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!)")!]

}

请帮帮我..

最佳答案

首先像这样初始化一个 KingfisherSource 类型的数组

var items = [KingfisherSource]()

然后执行您之前执行的操作并将每个 kingfisherSource 对象附加到 items 数组中。

for index in 0 ..< self.orderAttemptImageArray.count{
var kingfisherSource = KingfisherSource(urlString: "\(orderAttemptImageArray[index].mUrl!)")! as! KingfisherSource
items.append(kingfisherSource)
}

希望对您有所帮助。

关于arrays - 如何将动态数据快速获取到数组 KingFisher,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41736174/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com