我有一个应用程序,我正在使用YouTube API和Alamofire。使用YouTube API,我会收到包含视频标记数组的回复。像这样:
tags = (
tag1,
"tag2",
"tag3",
"tag4",
"tag5"
);
通常,您会收到类似
的回复title = "NEW Google Home Products!!";
然后您可以将字符串设置为
var videoTitle:String = ""
然后在Alamofire的回复中......
videoTitle = (items as AnyObject).value(forKeyPath: "statistics.commentCount") as! String
但是,因为标签会返回一个字符串数组,如上所示,此方法不起作用。如何为可以设置为标签数组的字符串数组创建变量?
答案 0 :(得分:0)
如何将其转换为String
s?
if let tags = (items as AnyObject).value(forKeyPath: "tags") as? [String] {
print(tags) //[tag1, tag2] ...
}