0

In my class I define a default port as follows:

private let DEFAULT_PORT: UInt16 = UInt16(47300)

(I also tried : private let DEFAULT_PORT: UInt16 = 47300 )

This should be perfectly ok as the maximum number of UInt16 is 65'535.

The app crashes in one method, though and the debugger shows that DEFAULT_PORT is equal to -18326.

How is this possible? Could it be a bug in Swift? I don't have a clue.

Jeyhey
  • 490
  • 3
  • 16
  • 1
    whats the error that you receive, how is the code being used in that method? what you have above looks ok so we need to know the rest of the information – Scriptable Jul 18 '16 at 12:49
  • There is no real error. I pass the port to create a UserAgent (voip) which fails and causes an error when trying to unwrap the UserAgent-instance. I put a breakpoint before anything gets executed and still have a value of -18326 for DEFAULT_PORT. – Jeyhey Jul 18 '16 at 12:56
  • when you say "it fails and causes an error" what does the error say? – Scriptable Jul 18 '16 at 13:03
  • Just the following for my UserAgent-Instance: "fatal error: unexpectedly found nil while unwrapping an Optional value" – Jeyhey Jul 18 '16 at 13:04
  • well DEFAULT_PORT is not nil... so it must be something else. I cannot help you without seeing the code, there's not much point in showing us working code and saying there's a problem somewhere else. provide the code so that we can try and replicate it – Scriptable Jul 18 '16 at 13:49
  • I investigated a bit more. My problem is not related to the the value of DEFAULT_PORT. The value shown in the debugger must be a bug in Xcode and not in Swift. – Jeyhey Jul 20 '16 at 09:03

1 Answers1

0

Ok, I investigated a bit more. My problem was not related to the value of DEFAULT_PORT.

Concerning the negative value in the debugger, it looks to me like a bug in Xcode and not in Swift. I did a few tests and Swift does all operations with the correct value.

To reproduce anyone can define private let DEFAULT_PORT: UInt16 = UInt16(47300) in the AppDelegate and put a Breakpoint in didFinishLaunchingWithOptions. You should then see -18326 as value in the debugger.

Jeyhey
  • 490
  • 3
  • 16