Ambiguous use of 'subscript' with NSArray & JSON

前端 未结 1 931
死守一世寂寞
死守一世寂寞 2021-01-23 09:17

I have looked through the similar topics in stackoverflow but none of those solutions seem to work for me.

I have an app that fetch video through youtube API . The follo

1条回答
  •  别那么骄傲
    2021-01-23 09:37

    The problem here is almost certainly that your JSON is defined as a type that could be an array or a dictionary. With Xcode 7.1 ambiguity enforcement was levelled up, so you need to explicitly cast it to something that can be subscripted by a string. This should sort you nicely:

    for video in (JSON as! NSDictionary)["items"] as! NSArray
    

    0 讨论(0)
提交回复
热议问题