1
let errorCodestring : String?

if let theError = errorCodestring {
    print(theError)
}

In the above code Xcode throws the error:

constant 'errorCodestring'being used before being initialized

What is wrong in the code and how to clear the error?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Vino
  • 11
  • 1
  • 1
    Please [search on an error](https://stackoverflow.com/search?q=%5Bswift%5D+constant+being+used+before+being+initialized) before posting. – rmaddy Nov 09 '18 at 17:47
  • 1
    @rmaddy: Well, it *is* a bit tricky, because you would not get an error with `var errorCodestring : String?`. Optional *variables* are implicitly initialized, but not optional constants. – Martin R Nov 09 '18 at 17:48

1 Answers1

2

You have to initialize the constant before using it.

let errorCodestring : String? = nil
Eric Aya
  • 69,473
  • 35
  • 181
  • 253