-4

Please help, I keep getting unexpectedly found nil.

I am very puzzled at how I can get around this?!

fatal error: unexpectedly found nil while unwrapping an Optional value

I have tried the following but no joy:

        if (destinationNameArray == NSString(string: "nil")){
            destinationNameArray = [String]()
        }

        if (lineNameArray[indexPath.row] == "nil"){
            lineNameArray[indexPath.row] = "none"
        }
Adi Prasetyo
  • 874
  • 1
  • 11
  • 35
jarv81178
  • 81
  • 6
  • what is this line: `destinationNameArray == NSString(string: "nil")` intended to do? – marosoaie Feb 20 '16 at 20:57
  • Possible duplicate of [Fatal error: unexpectedly found nil while unwrapping an Optional values](http://stackoverflow.com/questions/24643522/fatal-error-unexpectedly-found-nil-while-unwrapping-an-optional-values) – Lukesivi Feb 20 '16 at 20:57
  • `"nil"` != `nil` and please add the code where the error occurs. – vadian Feb 20 '16 at 21:00
  • means you are force unwrapping an optional value (by using an "!") which has a value of nil (it is not a string btw) – konrad.bajtyngier Feb 20 '16 at 21:00
  • ok so I have just done this to all my labels and I still get the error?! ` if let label1 = cell.tubeMode{ label1.text = lineNameArray[indexPath.row] }` – jarv81178 Feb 20 '16 at 21:31
  • I suggest to start with reading the Swift programming manual, right from the very start. The whole snippet seems wrong. – Eiko Feb 20 '16 at 22:35

1 Answers1

0

Use nil directly instead of "nil":

    if (destinationNameArray == nil){
        destinationNameArray = [String]()
    }
Stefan
  • 4,831
  • 8
  • 24
  • 48
  • I tried this but it says value of [string] can never be nil, comparison isn't allowed if (lineNameArray == nil){ lineNameArray = [String]() } – jarv81178 Feb 21 '16 at 10:32
  • `let lineName = object["lineName"].string as String! lineName.append(lineName)` – jarv81178 Feb 21 '16 at 12:04