AnyObject to Array?

后端 未结 5 2010
既然无缘
既然无缘 2021-01-01 09:49

I\'m using NSJSONSerialization as so:

let twData: AnyObject? = NSJSONSerialization.JSONObjectWithData(responseData, options: NSJSONReadingOption         


        
5条回答
  •  情话喂你
    2021-01-01 10:00

    This works in a playground:

    var data: Array>? = twData as? Array>
    

    the difference from your code is that twData does not require the ? at the end - it is an optional so the as? operator will take care of verifying that it can be case to an array of dictionaries - needless to say, if it's nil, as? will evaluate to nil

提交回复
热议问题