split now complains about missing “isSeparator”

后端 未结 1 1097
广开言路
广开言路 2020-12-06 17:24

After the latest upgrade of Swift 1.2, I can\'t figure out how to split a line of text into words. I used to do this:

let bits = split(value!, { $0 == \" \"}         


        
相关标签:
1条回答
  • 2020-12-06 18:09

    It seems that the order of the parameters changed in Swift 1.2:

    let bits = split(value!, maxSplit: Int.max, allowEmptySlices: false,
                     isSeparator: { $0 == " "})
    

    or, using the default values:

    let bits = split(value!, isSeparator: { $0 == " "})
    

    The predicate is now the last parameter and requires an external parameter name isSeparator because it is preceded by optional parameters.

    The advantage of this change is that you can use the trailing closure syntax:

    let bits = split(value!, maxSplit: Int.max, allowEmptySlices: false) { $0 == " " }
    

    or

    let bits = split(value!) { $0 == " " }
    
    0 讨论(0)
提交回复
热议问题