Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot assign value of type 'ArraySlice<User>' to type '[User]'

Tags:

ios

swift

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

like image 950
Shahbaz Akram Avatar asked Apr 12 '18 11:04

Shahbaz Akram


Video Answer


1 Answers

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))
like image 60
Dávid Pásztor Avatar answered Sep 26 '22 16:09

Dávid Pásztor