首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将动态数据导入数组KingFisher swift

如何将动态数据导入数组KingFisher swift
EN

Stack Overflow用户
提问于 2017-01-19 15:32:02
回答 1查看 522关注 0票数 0

我是新手。我用这个翠鸟从url获取图片..

这是原始代码..

代码语言:javascript
复制
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可以是一个,也可以是两个或多个。

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

代码语言:javascript
复制
let kingfisherSource = [KingfisherSource(urlString:"url[0]")!, KingfisherSource(urlString: "url[1]")!, KingfisherSource(urlString: "url[2]")!]

这是我的代码..但我不知道该怎么做..

代码语言:javascript
复制
for index in 0 ..< self.orderAttemptImageArray.count        {
    print(orderAttemptImageArray[index].mUrl!)

         var kingfisherSource = [KingfisherSource(urlString: "\(orderAttemptImageArray[index].mUrl!)")!]

    }

请帮帮我..

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-01-19 15:43:37

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

代码语言:javascript
复制
var items = [KingfisherSource]()

然后执行前面的操作&将每个kingfisherSource对象追加到items数组中。

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

希望能有所帮助。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41736174

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档