Calling a global function which has the same name as a member function

前端 未结 2 1290
既然无缘
既然无缘 2021-01-03 21:05

The Array type in Swift has a member function called sort, with its signature being sort(isOrderedBefore: (T, T) -> Bool). This fun

相关标签:
2条回答
  • 2021-01-03 21:21

    Wrap the global sort, for example,

    func my_sort<T>(arr: T[], pred: (T, T) -> Bool) -> T[] {
        return sort(arr, pred)
    }
    
    0 讨论(0)
  • 2021-01-03 21:30

    Chris Lattner suggests qualifying the name of the global function with Swift's default namespace, Swift. So you should be able to access the global version using: Swift.sort.

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