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
  • 314,917
  • 42
  • 532
  • 579
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,404
  • 1
  • 31
  • 57