Strange generic function appear in view controller after converting to swift 3

后端 未结 1 1121
陌清茗
陌清茗 2020-11-27 18:58

In my project, after converting to swift 3, a new function appeared before my ViewController class:

fileprivate func < 

        
相关标签:
1条回答
  • 2020-11-27 19:39

    That is interesting. Before the latest Swift 3, you could compare optional values, for example

    let a: Int? = nil
    let b: Int? = 4
    
    print(a < b) // true
    

    and nil was considered less than all non-optional values.

    This feature has been removed (SE-0121 – Remove Optional Comparison Operators) and the above code would fail to compile in Xcode 8 beta 6 with

    error: value of optional type 'Int?' not unwrapped; did you mean to use '!' or '?'?
    

    Apparently, the Swift migrator solves that problem for you by providing a custom < operator which takes two optional operands and therefore "restores" the old behavior.

    If you remove that definition then you should see where the comparison is done in your code. Then try to update your code and remove the optional comparisons.

    0 讨论(0)
提交回复
热议问题