30 lines
1.1 KiB
Swift
30 lines
1.1 KiB
Swift
//
|
|
// Array+Extensions.swift
|
|
// RxDataSources
|
|
//
|
|
// Created by Krunoslav Zaher on 4/26/16.
|
|
// Copyright © 2016 Krunoslav Zaher. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
import Foundation
|
|
|
|
extension Array where Element: SectionModelType {
|
|
mutating func moveFromSourceIndexPath(_ sourceIndexPath: IndexPath, destinationIndexPath: IndexPath) {
|
|
let sourceSection = self[(sourceIndexPath as NSIndexPath).section]
|
|
var sourceItems = sourceSection.items
|
|
|
|
let sourceItem = sourceItems.remove(at: (sourceIndexPath as NSIndexPath).item)
|
|
|
|
let sourceSectionNew = Element(original: sourceSection, items: sourceItems)
|
|
self[(sourceIndexPath as NSIndexPath).section] = sourceSectionNew
|
|
|
|
let destinationSection = self[(destinationIndexPath as NSIndexPath).section]
|
|
var destinationItems = destinationSection.items
|
|
destinationItems.insert(sourceItem, at: (destinationIndexPath as NSIndexPath).item)
|
|
|
|
self[(destinationIndexPath as NSIndexPath).section] = Element(original: destinationSection, items: destinationItems)
|
|
}
|
|
}
|