0

fatal error: unexpectedly found nil while unwrapping an Optional value

This is my code line:

let View = (VArray[0] as? [String : Any])?["views_count"] as! NSNumber

Can anyone help me apply try catch for this line? For Swift 3.1 of 4.

rmaddy
  • 307,833
  • 40
  • 508
  • 550
Jay Raval
  • 23
  • 3

1 Answers1

0

It's quite easy using optional

if let dictView = VArray[0] as? [String : Any], let viewsCount = dictView["views_count"] as? NSNumber {
    print(viewsCount)
} else {
    print("Cannot convert to NSNumber")
}
Sohil R. Memon
  • 9,176
  • 1
  • 30
  • 56