我有以下代码.该response.result.value
类型是Optional(AnyObject)
,我要检查
它的类型 [[String: AnyObject]]
打开可选项
检查数组的计数
如果...返回...声明,我更喜欢一个线卫
Alamofire.request(.GET, API.listArticle).responseJSON { response in print(response.result.value) guard let articles = response.result.value as? [[String: AnyObject]] where articles.count > 0 else { return } for article in articles { let entity = NSEntityDescription.insertNewObjectForEntityForName("Article", inManagedObjectContext: DBHelper.context()) as! Article entity.title = article["title"] entity.content = article["content"] } }
错误是article["content"]
行,
cannot subscript a value of type Dictionary
.
我还需要检查是否title
存在article
?它会崩溃还是什么都不做?