DataSource
@propertyWrapper
public class DataSource<Value>
Wrapper datasource of List or Grid dataSource = [Element] or dataSource = [[Element]]
Example:
struct ListView: View {
@DataSource var dataSource: [Model] = [Model]()
@DataSource var headerDataSource: [Model] = [Model]()
@DataSource var footerDataSource: [Model] = [Model]()
var body: View {
List(data:$dataSource){ data in
Row(data)
}
.sectionHeader($headerDataSource) { data in
Header(data)
}
.sectionFooter($footerDataSource) { data in
Footer(data)
}
.didSelectRow { (data, index) in
// Did Select row action
}
}
func appendData(data: Model) {
$dataSource.append(data)
$dataSource.apply()
}
}
-
Undocumented
Declaration
Swift
public var reloadAction: ((UITableView.RowAnimation) -> Void)? -
Undocumented
Declaration
Swift
public init<D>(_ value: Value) where Value == DataList<D> -
Undocumented
Declaration
Swift
public init<D>(_ value: Value) where Value == SectionDataList<D> -
Undocumented
Declaration
Swift
public init<D>(wrappedValue value: Value) where Value == DataList<D> -
Undocumented
Declaration
Swift
public init<D>(wrappedValue value: Value) where Value == SectionDataList<D> -
Undocumented
Declaration
Swift
public var projectedValue: DataSource<Value> { get } -
Undocumented
Declaration
Swift
public var wrappedValue: Value { get } -
apply the changes of data source on the List, use the specified animation.
Declaration
Swift
public func apply(with animation: UITableView.RowAnimation = UITableView.RowAnimation(rawValue: -1) ?? .none)Parameters
animationThe type of animation to use when the List changes.
-
prepare a viewnode from a element.
@DataSource var dataSource:[Int] = [Int]() $dataSource.prepareNode(from:data)Declaration
Swift
@discardableResult public func prepareNode<Element>(from element: Element) -> SelfParameters
elementThe element to prepare a view node.
Return Value
Self
-
prepare a viewnode from a elements.
@DataSource var dataSource:[Int] = [Int]() $dataSource.prepareNode(from:data)Declaration
Swift
@discardableResult public func prepareNode<Element>(from elements: DataList<Element>) -> SelfParameters
elementsThe elements to prepare view nodes.
Return Value
Self
-
Adds a new element at the end of the dataSource. dataSource = [Element]
@DataSource var dataSource:[Int] = [Int]() $dataSource.append(1) $dataSource.append(2) $dataSource.append(3) print(dataSource) // Prints "[1, 2, 3]"Declaration
Swift
@discardableResult public func append<Element>(_ newElement:Element) -> Self where Value == DataList<Element>Parameters
newElementThe element to append to the dataSource.
Return Value
Self
-
Adds a new element at the end of the dataSource. dataSource = [[Element]]
@DataSource var dataSource:[[Int][ = [[Int]]() var numbers1 = [1, 2, 3] var numbers2 = [4, 5, 6] var numbers3 = [7, 8, 9] $dataSource.append(numbers1) $dataSource.append(numbers2) print("numbers1:\(dataSource[0])") print("numbers2:\(dataSource[1])") // Prints "numbers1:[1, 2, 3]" // Prints "numbers1:[4, 5, 6]"Declaration
Swift
@discardableResult public func append<Element>(_ newElement:DataList<Element>) -> Self where Value == SectionDataList<Element>Parameters
newElementThe element to append to the dataSource.
Return Value
Self
-
Adds a new element at the end of the specified section of the dataSource dataSource = [[Element]]
@DataSource var dataSource:[[Int]] = [[1, 2, 3],[4, 5, 6],[7, 8, 9]] var numbers = 10 $dataSource.append(numbers,section:1) print("numbers1:\(dataSource)") // Prints "[[1, 2, 3],[4, 5, 6, 10],[7, 8, 9]]"Declaration
Swift
@discardableResult public func append<Element>(_ newElement:Element,section:Int) -> Self where Value == SectionDataList<Element>Parameters
newElementThe element to append to the dataSource.
sectionThe specified section of the dataSource
Return Value
Self
-
Adds the elements of a [Element] to the end of the specified section of the dataSource. dataSource = [[Element]]
@DataSource var dataSource:[[Int][ = [[1, 2, 3],[4, 5, 6],[7, 8, 9]] var numbers = [10, 20, 30] $dataSource.append(numbers,section:1) print("numbers1:\(dataSource)") // Prints "[[1, 2, 3],[4, 5, 6,10, 20, 30],[7, 8, 9]]"Declaration
Swift
@discardableResult public func append<Element>(contentsOf newElements:DataList<Element>,section:Int) -> Self where Value == SectionDataList<Element>Parameters
newElementsThe element to append to the dataSource.
sectionThe specified section of the dataSource
Return Value
Self
-
Adds the elements of a [Element] to the end of the dataSource dataSource = [Element]
@DataSource var dataSource:[Int[ = [Int]() var numbers = [1, 2, 3, 4, 5] $dataSource.append(contentsOf: numbers) print(numbers) // Prints "[1, 2, 3, 4, 5]"Declaration
Parameters
newElementsThe elements to append to the dataSource.
Return Value
Self
-
Adds the elements of a [[Element]] to the end of the dataSource. dataSource = [[Element]]
@DataSource var dataSource:[[Int]] = [[Int]]]() var numbers = [[1, 2, 3, 4, 5],[6,7,8]] $dataSource.append(contentsOf: numbers) print(numbers) // Prints "[[1, 2, 3, 4, 5],[6,7,8]]"Declaration
Swift
@discardableResult public func append<Element>(contentsOf newElements:SectionDataList<Element>) -> Self where Value == SectionDataList<Element>Parameters
newElementsThe elements to append to the dataSource.
Return Value
Self
-
Inserts the elements of a [Element] to the end of the dataSource. dataSource = [Element]
@DataSource var dataSource:[Int] = [1, 2, 3, 4, 5] var numbers = [10, 20, 30] var indexPaths = [IndexPath(row: 0, section: 0),IndexPath(row: 1, section: 0),IndexPath(row: 2, section: 0)] $dataSource.insert(datas: numbers, at: indexPaths) print(dataSource) // Prints "[10,20,30,1, 2, 3, 4, 5]"Declaration
Swift
@discardableResult public func insert<Element>(datas:[Element],at indexPaths: [IndexPath]) -> Self where Value == DataList<Element>Parameters
datasThe new elements to insert into the dataSource.
indexPathsThe positions at which to insert the new element.
Return Value
Self`.
-
Inserts the elements of a sequence into the dataSource at the specified position. dataSource = [Element]
@DataSource var dataSource:[Int] = [1, 2, 3, 4, 5] $dataSource.insert(contentsOf: 100...103, at: 3) print(numbers) // Prints "[1, 2, 3, 100, 101, 102, 103, 4, 5]"Calling this method may invalidate any existing indices for use with this dataSource.
Declaration
Swift
@discardableResult public func insert<Element>(contentsOf datas:[Element],at position:Int) -> Self where Value == DataList<Element>Parameters
newElementsThe new elements to insert into the dataSource.
positionThe position at which to insert the new elements.
indexmust be a valid index of the collection. -
Inserts the elements of a [Element] to the end of the dataSource dataSource = [[Element]]
@DataSource var dataSource:[[Int]] = [[1,2],[3,4],[5,6]] var numbers = [10, 20, 30] var indexPaths = [IndexPath(row: 1, section: 0),IndexPath(row: 1, section: 1),IndexPath(row: 0, section: 2)] $dataSource.insert(datas: numbers, at: indexPaths) print(dataSource) // Prints "[[1,10,2],[3,20,4],[30,5,6]]"Declaration
Swift
@discardableResult public func insert<Element>(datas:[Element],at indexPaths: [IndexPath]) -> Self where Value == SectionDataList<Element>Parameters
datasThe new elements to insert into the dataSource.
indexPathsThe positions at which to insert the new element.
Return Value
Self`.
-
Inserts the elements of a [Element] to the end of the specified section of the dataSource. dataSource = [[Element]]
@DataSource var dataSource:[[Int]] = [[1,2],[3,4],[5,6]] var numbers = [10, 20, 30] var indexPaths = [IndexPath(row: 1, section: 0),IndexPath(row: 1, section: 1),IndexPath(row: 0, section: 2)] $dataSource.insert(datas: numbers, at: indexPaths) print(dataSource) // Prints "[[1,10,2],[3,20,4],[30,5,6]]"Declaration
Swift
@discardableResult public func insert<Element>(contentsOf datas:[Element],at position: Int, section:Int) -> Self where Value == SectionDataList<Element>Parameters
datasThe new elements to insert into the dataSource.
indexPathsThe positions at which to insert the new element.
sectionThe specified section of the dataSource.
Return Value
Self`.
-
Inserts a new element at the specified position. dataSource = [Element]
@DataSource var dataSource:[Int] = [1, 2, 3, 4, 5] $dataSource.insert(data:10, at: IndexPath(row: 1, section: 0)) print(dataSource) // Prints "[1,10, 2, 3, 4, 5]"Declaration
Swift
@discardableResult public func insert<Element>(data:Element,at indexPath: IndexPath) -> Self where Value == DataList<Element>Parameters
datasThe new element to insert into the dataSource.
indexPathThe position at which to insert the new element.
Return Value
Self`.
-
Inserts a new element at the specified position. dataSource = [Element]
@DataSource var dataSource:[[Int]] = [[1,2],[3,4],[5,6]] $dataSource.insert(data:10, at: IndexPath(row: 1, section: 1)) print(dataSource) // Prints "[[1,2],[3,10,4],[5,6]]"Declaration
Swift
@discardableResult public func insert<Element>(data:Element,at indexPath: IndexPath) -> Self where Value == SectionDataList<Element>Parameters
datasThe new element to insert into the dataSource.
indexPathThe position at which to insert the new element.
Return Value
Self`.
-
Removes all elements from the dataSource.
Declaration
Swift
@discardableResult public func clear<Element>() -> Self where Value == DataList<Element> -
Removes all elements from the dataSource.
Declaration
Swift
@discardableResult public func clear<Element>() -> Self where Value == SectionDataList<Element> -
Removes all elements from the dataSource.
Declaration
Swift
@discardableResult public func clear<Element>(at section: Int) -> Self where Value == SectionDataList<Element> -
delete the element at the specified position from dataSource. dataSource = [Element]
@DataSource var dataSource:[Int] = [1, 5, 9, 12, 15, 13, 12] $dataSource.delete(IndexPath(row: 1, section: 0)) print(dataSource) // Prints "[1, 9, 12, 15, 13, 12]"Declaration
Swift
@discardableResult public func delete<Element>(at indexPath: IndexPath) -> Self where Value == DataList<Element>Parameters
indexPathThe position of the element to remove.
Return Value
Self.
-
delete the element at the specified position from dataSource. dataSource = [[Element]]
@DataSource var dataSource:[Int] = [[1, 5], [9, 12], [15, 13, 12]] $dataSource.delete(IndexPath(row: 1, section: 1)) print(dataSource) // Prints "[[1, 5], [9], [15, 13, 12]]"Declaration
Swift
@discardableResult public func delete<Element>(at indexPath: IndexPath) -> Self where Value == SectionDataList<Element>Parameters
indexPathThe position of the element to delete.
Return Value
Self.
-
delete the element at the specified positions from dataSource. dataSource = [Element]
@DataSource var dataSource:[Int] = [1, 5, 9, 12, 15, 13, 12] $dataSource.delete(at:[IndexPath(row: 1, section: 0),IndexPath(row: 2, section: 0),IndexPath(row: 1, section: 0)]) print(dataSource) // Prints "[1, 15, 13, 12]"Declaration
Swift
@discardableResult public func delete<Element>(at indexPaths: [IndexPath]) -> Self where Value == DataList<Element>Parameters
indexPathsThe positions of the element to delete.
Return Value
Self.
-
delete the element at the specified position from dataSource. dataSource = [[Element]]
@DataSource var dataSource:[[Int]] = [[1, 5, 9, 12, 15, 13, 12],[1, 5], [9, 12], [15, 13, 12,24,1]] $dataSource.delete(at:[IndexPath(row: 1, section: 0),IndexPath(row: 2, section: 0),IndexPath(row: 3, section: 0),IndexPath(row: 1, section: 3),IndexPath(row: 1, section: 3)]) print(dataSource) // Prints "[[1, 15, 13, 12], [1, 5], [9, 12], [15, 24, 1]]"Declaration
Swift
@discardableResult public func delete<Element>(at indexPaths: [IndexPath]) -> Self where Value == SectionDataList<Element>Parameters
indexPathsThe positions of the element to delete.
Return Value
Self.
-
delete the section at the specified position from dataSource. dataSource = [[Element]]
@DataSource var dataSource:[[Int]] = [[1, 5, 9, 12, 15, 13, 12],[1, 5], [9, 12], [15, 13, 12,24,1]] $dataSource.deleteSection(at:[1,2]) print(dataSource) // Prints "[[1, 5, 9, 12, 15, 13, 12],[15, 13, 12,24,1]]"Declaration
Swift
@discardableResult public func delete<Element>(sections: IndexSet) -> Self where Value == SectionDataList<Element>Parameters
sectionsThe positions of the section to delete.
Return Value
Self.
-
replace the element of [Element] at the specified positions from dataSource. dataSource = [Element]
@DataSource var dataSource:[Int] = [1, 5, 9, 12, 15, 13, 12] $dataSource.replace(datas:[10,20], at:[IndexPath(row: 1, section: 0),IndexPath(row: 2, section: 0)) print(dataSource) // Prints "[1, 10, 20, 12, 15, 13, 12]"Declaration
Swift
@discardableResult public func replace<Element>(datas:[Element],at replaceIndexPaths: [IndexPath]) -> Self where Value == DataList<Element>Parameters
datasThe new elements to replace into the dataSource.
indexPathsThe positions of the element to replace.
Return Value
Self.
-
replace the element of [Element] at the specified positions from dataSource. dataSource = [Element]
@DataSource var dataSource:[[Int]] = [[1, 5, 9, 12, 15, 13, 12],[1, 5], [15, 13, 12,24,1]] $dataSource.replace(datas:[10,20,30], at:[IndexPath(row: 1, section: 0),IndexPath(row: 1, section: 1),IndexPath(row: 2, section: 2)]) print(dataSource) // Prints "[[1, 10, 9, 12, 15, 13, 12],[1, 20], [15, 13, 30,24,1]]"Declaration
Swift
@discardableResult public func replace<Element>(datas:[Element],at replaceIndexPaths: [IndexPath]) -> Self where Value == SectionDataList<Element>Parameters
datasThe new elements to replace into the dataSource.
indexPathsThe positions of the element to replace.
Return Value
Self.
-
replace the element at the specified positions from dataSource. dataSource = [Element]
@DataSource var dataSource:[Int] = [1, 5, 9, 12, 15, 13, 12] $dataSource.replace(data:10, at:IndexPath(row: 3, section: 0)) print(dataSource) // Prints "[1, 5, 9, 10, 15, 13, 12]"Declaration
Swift
@discardableResult public func replace<D>(data:D,at indexPath: IndexPath) -> Self where Value == DataList<D>,D:ArgoKitIdentifiableParameters
dataThe new element to replace into the dataSource.
indexPathThe position of the element to replace.
Return Value
Self.
-
replace the element at the specified position from dataSource. dataSource = [Element]
@DataSource var dataSource:[[Int]] = [[1, 5, 9, 12, 15, 13, 12],[1, 5, 7], [15, 13, 12,24,1]] $dataSource.replace(datas:30, at:IndexPath(row: 1, section: 1)) print(dataSource) // Prints "[[1, 5, 9, 12, 15, 13, 12],[1, 30, 7], [15, 13, 12,24,1]]"Declaration
Swift
@discardableResult public func replace<Element>(data:Element,at indexPath: IndexPath) -> Self where Value == SectionDataList<Element>Parameters
dataThe new elements to replace into the dataSource.
indexPathThe position of the element to replace.
Return Value
Self.
-
move the element at the specified position to new position for dataSource. dataSource = [Element]
@DataSource var dataSource:[Int]] = [1, 5, 9, 12, 15, 13, 12] $dataSource.move(at:IndexPath(row: 1, section: 0), at:IndexPath(row: 2, section: 0)) print(dataSource) // Prints "[1, 9, 5, 12, 15, 13, 12]"Declaration
Swift
@discardableResult public func move<Element>(at indexPath: IndexPath, to newIndexPath: IndexPath) ->Self where Value == DataList<Element>Parameters
indexPathThe position that element will move from.
newIndexPathThe new position that element will move to.
Return Value
Self.
-
move the element at the specified position to new position for dataSource. dataSource = [[Element]]
@DataSource var dataSource:[[Int]] = [[1, 5, 9, 12, 15, 13, 12],[1, 5, 7], [15, 13, 12,24,1]] $dataSource.move(at:IndexPath(row: 1, section: 0), at:IndexPath(row: 2, section: 1)) print(dataSource) // Prints "[[1, 9, 12, 15, 13, 12],[1, 5,5, 7], [15, 13, 12,24,1]]"Declaration
Swift
@discardableResult public func move<Element>(at indexPath: IndexPath, to newIndexPath: IndexPath) ->Self where Value == SectionDataList<Element>Parameters
indexPathThe position that element will move from.
newIndexPathThe new position that element will move to.
Return Value
Self.
-
The number of elements in the dataSource. dataSource = [Element]
Declaration
Swift
public func count<Element>() -> Int where Value == DataList<Element> -
The number of elements in the dataSource. dataSource = [[Element]]
Declaration
Swift
public func count<Element>() -> Int where Value == SectionDataList<Element> -
The number of elements at the specified section from dataSource. dataSource = [[Element]]
Declaration
Swift
public func count<Element>(section: Int) -> Int where Value == SectionDataList<Element>Parameters
sectionThe specified section
-
Accesses the element at the specified position from dataSource. dataSource = [Element] The following example uses indexed subscripting to update an array’s second element. After assigning the new value (
15) at a specific position, that value is immediately available at that same position.@DataSource var dataSource:[Int] = [1, 2, 3, 4, 5] streets[1] = 15 print(streets[1]) // Prints "15"Declaration
Swift
public subscript<Element>(row: Int) -> Element where Value == DataList<Element> { get set }Parameters
indexThe position of the element to access.
-
Accesses the element at the specified position from dataSource. dataSource = [[Element]] The following example uses indexed subscripting to update an array’s second element. After assigning the new value (
[10,11,12]) at a specific position, that value is immediately available at that same position.@DataSource var dataSource:[[Int]] = [[1, 2, 3],[4, 5, 6],[7, 8, 9]] $dataSource[1] = [10,11,12] print($dataSource[1]) // Prints "[10,11,12]"Declaration
Swift
public subscript<Element>(row: Int) -> [Element] where Value == SectionDataList<Element> { get set }Parameters
indexThe position of the element to access.
-
Accesses the element at the specified position of specified section from dataSource. dataSource = [[Element]] The following example uses indexed subscripting to update an array’s second element of first section. After assigning the new value (
15) at a specific position, that value is immediately available at that same position.@DataSource var dataSource:[[Int]] = [[1, 2, 3],[4, 5, 6],[7, 8, 9]] $dataSource[1,0] = 15 print($dataSource[1]) // Prints "15"Declaration
Swift
public subscript<Element>(row: Int, section: Int) -> Element where Value == SectionDataList<Element> { get set }Parameters
indexThe position of the element to access.
-
get the element at the specified indexPath from dataSource. dataSource = [Element]
@DataSource var dataSource:[Int] = [1, 5, 9, 12, 15, 13, 12] let value:Int = $dataSource.value(indexPath:IndexPath(row: 1, section: 0)) print(value) // Prints "5"Declaration
Swift
public func value<Element>(at indexPath: IndexPath) -> Element? where Value == DataList<Element>Parameters
indexPathThe specified position
Return Value
element for position.
-
get the element at the specified indexPath from dataSource. dataSource = [[Element]]
@DataSource var dataSource:[Int]] = [[1, 5, 9, 12, 15, 13, 12],[1, 5, 7], [15, 13, 12,24,1]] let value:Int = $dataSource.value(at:IndexPath(row: 2, section: 1)) print(value) // Prints "7"Declaration
Swift
public func value<Element>(at indexPath: IndexPath) -> Element? where Value == SectionDataList<Element>Parameters
indexPathThe specified position
Return Value
element for position.
-
get the element at the specified section from dataSource. dataSource = [[Element]]
@DataSource var dataSource:[Int]] = [[1, 5, 9, 12, 15, 13, 12],[1, 5, 7], [15, 13, 12,24,1]] let value:Int = $dataSource.value(at:IndexPath(row: 2, section: 1)) print(value) // Prints "7"Declaration
Swift
public func value<Element>(at section: Int) -> [Element]? where Value == SectionDataList<Element>Parameters
sectionThe specified section
Return Value
elements for position.
-
The first element of the dataSource. dataSource = [Element]
If the dataSource is empty, the value of this property is
nil.@DataSource var dataSource:[Int]] = [10, 20, 30, 40, 50] if let firstNumber:Int = $dataSource.first { print(firstNumber) } // Prints "10"Declaration
Swift
public func first<Element>() -> Element? where Value == DataList<Element>Return Value
the first element.
-
The last element of the dataSource. dataSource = [Element]
If the dataSource is empty, the value of this property is
nil.@DataSource var dataSource:[Int]] = [10, 20, 30, 40, 50] if let firstNumber:Int = $dataSource.first() { print(firstNumber) } // Prints "50"Declaration
Swift
public func last<Element>() -> Element? where Value == DataList<Element>Return Value
the last element.
-
The first element of the dataSource. dataSource = [[Element]]
If the dataSource is empty, the value of this property is
nil.@DataSource var dataSource:[Int]] = [[10, 20, 30, 40, 50],[10,20],[30,40]] if let firstNumber:[Int] = $dataSource.first() { print(firstNumber) } // Prints "[10, 20, 30, 40, 50]"Declaration
Swift
public func first<Element>() -> [Element]? where Value == SectionDataList<Element>Return Value
the first element.
-
The last element of the dataSource. dataSource = [[Element]]
If the dataSource is empty, the value of this property is
nil.@DataSource var dataSource:[Int]] = [[10, 20, 30, 40, 50],[10,20],[30,40]] if let firstNumber:[Int] = $dataSource.last() { print(firstNumber) } // Prints "[10, 20, 30, 40, 50]"Declaration
Swift
public func last<Element>() -> [Element]? where Value == SectionDataList<Element>Return Value
the last element.
DataSource Class Reference