代码之家  ›  专栏  ›  技术社区  ›  Jacob Cavin Au Ris

使用YouTube API标记创建字符串数组

  •  0
  • Jacob Cavin Au Ris  · 技术社区  · 7 年前

    我有一个应用程序,我正在使用YouTube API和Alamofire。使用YouTube API,我得到了一个带有视频标记数组的响应。这样地:

    tags =         (
                tag1,
                "tag2",
                "tag3",
                "tag4",
                "tag5"
            );
    

    通常,你会得到这样的回答

    title = "NEW Google Home Products!!";
    

    var videoTitle:String = ""
    

    然后在阿拉莫菲尔的回复中。。。

    videoTitle = (items as AnyObject).value(forKeyPath: "statistics.commentCount") as! String
    

    但是,正如您在上面看到的那样,由于标记返回一个字符串数组,因此该方法将不起作用。如何为可以设置为标记数组的字符串数组创建变量?

    1 回复  |  直到 7 年前
        1
  •  0
  •   glyvox    7 年前

    将其投射到一系列 String s

    if let tags = (items as AnyObject).value(forKeyPath: "tags") as? [String] {
        print(tags) //[tag1, tag2] ...
    }