-3

Error found from this line: self.picture.image = UIImage(named: pictures[closestBeacon.minor.integerValue]!)

How to solve?

Yp Ng
  • 5
  • 3
  • 1
    Read this: [Apple Swift Documentation, The Basics: Optionals](https://developer.apple.com/library/watchos/documentation/Swift/Conceptual/Swift_Programming_Language/TheBasics.html#//apple_ref/doc/uid/TP40014097-CH5-ID330). – Eric Aya Oct 27 '15 at 15:07
  • 2
    Possible duplicate of [What does an exclamation mark mean in the Swift language?](http://stackoverflow.com/questions/24018327/what-does-an-exclamation-mark-mean-in-the-swift-language) – Eric Aya Oct 27 '15 at 15:08
  • Probably your `pictures` array contains nil at `closestBeacon.minor.integerValue` index. You should read articles metioned above – Martin Makarsky Oct 27 '15 at 15:16
  • 1
    Question shows no effort. Please explain what effort was made in attempting to resolve the issue prior to posting. – Max MacLeod Oct 27 '15 at 17:13

1 Answers1

0

You can prevent the crash by safely unwrapping pictures[closetBeacon.minor.integerValue] with an if let statement.

if let myImage = pictures[closetBeacon.minor.integerValue] {
self.picture.image = UIImage(named: myImage)

}

vivek takrani
  • 3,858
  • 2
  • 19
  • 33