1

I converted my project to swift 3, but stuck on following sequence. How to convert split function to swift 3.

    let myString = " key=value "

    let myData = myString.characters.split(1, allowEmptySlices: true, isSeparator: { $0 == "=" }).map(String.init)

    if let postValue = (valueWithData.count > 1 ? valueWithData[1] : nil) as String? {
       postData += "\(valueWithData[0])=\(postValue)&"                      
     }

I need get key value from myString. Got error:

'split(_:allowEmptySlices:isSeparator:)' has been explicitly marked unavailable here

Arti
  • 7,356
  • 12
  • 57
  • 122
  • 2
    http://stackoverflow.com/questions/25226940/swift-version-of-componentsseparatedbystring has code for Swift 1, 2, and 3. – Martin R Oct 02 '16 at 15:31
  • 3
    You can also type `myString.characters.split` in Xcode and see all available completions ... – Martin R Oct 02 '16 at 15:33
  • 2
    In a playground you get a more enlightening error message: `error: 'split(_:allowEmptySlices:isSeparator:)' is unavailable: call 'split(maxSplits:omittingEmptySubsequences:whereSeparator:)' and invert the 'allowEmptySlices' argument` – vadian Oct 02 '16 at 15:36
  • allowEmptySlices is not allow now, but what to do... – Arti Oct 03 '16 at 07:42

0 Answers0