Below is my code snippet in ObjC
NSDictionary *json;
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"realstories" ofType:@"json"];
NSData *data = [NSData dataWithContentsOfFile:filePath];
json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
I've tried using its Siwft equivalent this way:
var json = [AnyHashable:Any]()
let filePath: String? = Bundle.main.path(forResource: "realstories", ofType: "json")
let data = NSData(contentsOfFile:filePath!)
json = ((NSKeyedUnarchiver.unarchiveObject(with: data as! Data) as! NSDictionary) as! [AnyHashable:Any])
But I am stuck in error:
unexpectedly found nil while unwrapping an Optional value
Tried reading about it Here. But, could not get the error resolved!