Следующий код покажет, что «Значение типа« Любой »не имеет индексов»
if let postDictionary = jsonDictionary["post"] as? [String: AnyObject]
class FeedController: UICollectionViewController, UICollectionViewDelegateFlowLayout {
var posts = [Post]()
override func viewDidLoad() {
super.viewDidLoad()
if let path = Bundle.main.path(forResource: "single_post", ofType: "json") {
do {
let data = try(NSData(contentsOfFile: path, options: NSData.ReadingOptions.mappedIfSafe))
let jsonDictionary = try(JSONSerialization.jsonObject(with: data as Data, options: .mutableContainers))
if let postDictionary = jsonDictionary["post"] as? [String: AnyObject] {
let post = Post()
post.setValuesForKeysWithDictionary(postDictionary)
self.posts = [post]
}
print(jsonDictionary)
} catch let err {
print(err)
}
}