-1

i'm developing new iphone app , the problem is when i'm running that application shows for me error in one code inserted as below

https://drive.google.com/file/d/0Bz6LRAJzLaW2OGJSVmo3WE8yblk/view?usp=sharing

it's working fine with another viewcontroller and another swift file but not working with that this viewcontroller and swift file

see below working with infoviewcontroller , but not working with infromationviewcontroller , tried to change between two files but still there an error

https://drive.google.com/file/d/0Bz6LRAJzLaW2QVJUaC1EdndsX1E/view?usp=sharing

hope someone helps me about that case.

regards; Khalid bAdra

Gunone
  • 3
  • 3
  • Post the test from the errors, not links to screenshots of them. – nhgrif Mar 19 '16 at 13:19
  • I'd probably consider this question to be a duplicate of [this question](http://stackoverflow.com/q/24018327/2792531) which provides the answer needed (even if the question asked is not quite the same). – nhgrif Mar 19 '16 at 13:21
  • thx for your replaying , what is mean to post test from error do you mean to upload the application , 2nd comment different problem but with same replay and solution regards – Gunone Mar 20 '16 at 05:47

1 Answers1

0

If you look in the console in your image you can see the text fatal error: unexpectedly found nil while unwrapping an Optional value

That means that you are trying to do something (unwrap the value in this case) with an object that is nil.

If you look at the line highlighted with red in your image, then that is where the crash occurred. You can see that you are trying to set the value of your detailsLabel.text to currentPic!.notes

Your currentPic is a Photo?, question mark meaning Optional, Optional meaning: it can be something or it can be nothing. The ! in currentPic!.notes means that you are telling the compiler to just unwrap the optional, nil value or no nil value. This is normally a bad thing to do, because, as you can see here, if it is nil, then you receive a crash when for instance you try to use nil to set the text of a UILabel.

So, a couple of things for you to check.

  1. is your detailsLabel connected properly to an Outlet (it seems so based on your image, but...you know, better safe than sorry :-))
  2. Try unwrapping currentPic safely:

    if let currentPic = currentPic {
        detailsLabel.text = currentPic.notes
    }
    
  3. If safe unwrapping works, then you could start looking at why your currentPic variable is nil. It should probably be initialised with some value before you start using it in viewDidLoad(), maybe it should be sent along when you navigate from one page to another. In any case, you need to initialise it to something before you try to use it in viewDidLoad()

Hope that helps you.

pbodsk
  • 6,787
  • 3
  • 21
  • 51
  • your code worked so fine i'll keep these information for future also. by the way i'm still new to programming these information will help me in future to understand it after get better to swift. really thanks for you for your replaying . – Gunone Mar 19 '16 at 17:36
  • You're welcome. Optionals is one of those things that might be a bit hard to understand when you start out writing Swift code, but when you get the hang of them they're actually quite useful. Just remember that force unwrapping (with !) will usually lead to trouble at some later point as you just found out the hard way. It is often better to safely unwrap with `if let` or a `guard` statement. – pbodsk Mar 19 '16 at 18:08