Convert Int to UInt32 in Swift

前端 未结 3 1509
悲&欢浪女
悲&欢浪女 2021-02-11 13:33

Im making a Tcp client and therefore using the CFStreamCreatePairWithSocketToHost which is expecting an UInt32 for the second parameter.

Here is a sample of

3条回答
  •  天命终不由人
    2021-02-11 13:45

    It's very simple:

    let int: Int = 40
    let uint = UInt32(i)
    

    in your case, just pass

    UInt32(Port)
    

    For a port is not a problem, but in other cases be sure to take care of overflow

    Side note: in swift it's good practice to name variables using lower camel case, so with the first letter in lowercase

提交回复
热议问题