首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在swift中从API调用传递json数组的所有成员。

在swift中从API调用传递json数组的所有成员。
EN

Stack Overflow用户
提问于 2018-06-02 08:17:25
回答 1查看 155关注 0票数 1

嗨,我有一个项目,我实现了ImageSlideshow和sdwebimage。图像是通过API调用获得的,但在ImageSlideshow的文档中,SDwebImages的实现如下所示

let sdWebImageSource = [SDWebImageSource(urlString: "https://images.unsplash.com/photo-1432679963831-2dab49187847?w=1080")!, SDWebImageSource(urlString: "https://images.unsplash.com/photo-1447746249824-4be4e1b76d66?w=1080")!, SDWebImageSource(urlString: "https://images.unsplash.com/photo-1463595373836-6e0b0a8ee322?w=1080")!]

它工作得很好,但对于我自己的项目,我有一个数组中的所有图像,我想在ImageSlideshow中显示这些图像。我不知道图像的数量,所以很难对其进行硬编码,所以我如何传递图像数组。ProductServices.instance.selectedProduct?.productImg[0])这给了我第一个索引处的图像。图像可以达到第五级索引。我怎么才能通过这个?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-02 08:24:24

你可以试试

var allImages = [SDWebImageSource]()
if let allStr = ProductServices.instance.selectedProduct?.productImg {
    for str in allStr {
       allImages.append(SDWebImageSource(urlString:str))  
   }
}

if allImages.isEmpty {
   // display custom image // or add it's default str 
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50652391

复制
相关文章

相似问题

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