9

I want to divide Model array into two different arrays by using prefix , postfix

let data = serverResponse.data as! [User]
collectionData = data.prefix(upTo: 10)
tableData =  data.suffix(from: 11)

enter image description here

Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
Shahbaz Akram
  • 1,598
  • 3
  • 28
  • 45

1 Answers1

28

You need to convert the array slices returned by prefix and suffix to arrays by calling the initializer of Array accepting an ArraySlice.

let data = serverResponse.data as! [User]
collectionData = Array(data.prefix(upTo: 10))
tableData =  Array(data.suffix(from: 11))
Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116