Instead of JSONSerialization.jsonObject(with:)
you are using NSKeyedUnarchiver
, Also use native Data
instead of NSData
.
var json = [AnyHashable:Any]()
if let filePath = Bundle.main.path(forResource: "realstories", ofType: "json"),
let data = try? Data(contentsOf: URL(fileURLWithPath: filePath)),
let dic = (try? JSONSerialization.jsonObject(with: data)) as? [AnyHashable:Any] {
json = dic
}
solved Objective – C to Swift : NSData with NSJSONSerialisation