0

split() in swift 3 is deprecated. What will be alternate for below code:

var fullNameArr = split(str) {$0 == "@"}
CinCout
  • 9,486
  • 12
  • 49
  • 67
P.ECS
  • 5
  • 3

1 Answers1

1
let world = "Hello, world!".characters.suffix(6).dropLast()
String(world) // β†’ "world"

Here split, which returns an array of subsequences, is also used for string processing. It’s defined like that:

extension Collection {
func split(maxSplits: Int = default,
    omittingEmptySubsequences: Bool = default,
    whereSeparator isSeparator: (Self.Iterator.Element) throws -> Bool) rethrows
    -> [AnySequence<Self.Iterator.Element>]
}

For example:

let commaSeparatedArray = "a,b,c".characters.split { $0 == "," }
commaSeparatedArray.map(String.init) // β†’ ["a", "b", "c"]

For more detail in split in swift 3

Kallz
  • 3,244
  • 1
  • 20
  • 38