Swift: split array with map stride advance
Do you want to split an array in consecutive or NOT consecutive sequence? With Swift this will be easy but a bit complicate to understand. Anyway, below the code for split your array using map, stride and advance:
let tempDataSource = ["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19"] let sections = 4 //split array in multiple arrays with NOT consecutive sequence let a = map(stride(from:0 , to: sections, by: 1)) { map(stride(from:$0 , to: tempDataSource.count, by: sections)) { tempDataSource[$0] } } println(a[0]) let offset = tempDataSource.count%sections > 0 ? 1: 0 let split = (Int)(tempDataSource.count/sections) + offset var b: [ArraySlice<String>] = [] //split array in multiple arrays with consecutive sequence b = map(stride(from:0 , to: tempDataSource.count, by: split)) { tempDataSource[$0..<advance($0, split, tempDataSource.count)] } println(b[0])











