Elements
@available(*, deprecated, message: "Migrate to https://github.com/stanwood/SourceModel_iOS")
open class Elements<Element> : DataType, Codable where Element : Type, Element : Decodable, Element : Encodable, Element : Equatable
Elements holds an array of element types.
Important: only supports a single section dataType. For a more complex solution, please conform to the
DataType
protocol.
Example: DataSource and Delegate design
let items = [Element(id: "1"), Element(id: "2")]
self.objects = Stanwood.Elements<Element>(items: items)
self.dataSource = ElementsDataSource(dataObject: elements)
self.delegate = ElementsDelegate(dataObject: elements)
self.collectionView.dataSource = self.dataSource
self.collectionView.delegate = self.delegate
See also
-
Items of elements
Declaration
Swift
public var items: [Element]
-
Declaration
Swift
public static var identifier: String { get }
-
Number of items
Declaration
Swift
open var numberOfItems: Int { get }
-
Elements only supports a single section.
See also
DataType
for multiple section optionDeclaration
Swift
open var numberOfSections: Int { get }
Return Value
current section
-
Initializer of Elements
Declaration
Swift
public init(items: [Element])
Parameters
items
[Element]<Type & Equatable & Codable>
-
Subscript to get an item in row.
See also
Declaration
Swift
open subscript(indexPath: IndexPath) -> Type? { get }
Parameters
indexPath
IndexPath location of an item at row
Return Value
Optional<Type>
-
Returns the cell type at indexPath
Declaration
Swift
open func cellType(forItemAt indexPath: IndexPath) -> Fillable.Type?
-
Append an item or insert at index
Declaration
Swift
public func insert(item: Element, at index: Int)
Parameters
item
[Typeable] index
Index
-
Append an item or insert at index
Declaration
Swift
public func append(_ item: Element)
Parameters
item
[Typeable] -
Move an item to index.
Declaration
Swift
public func move(_ item: Element, to index: Int)
Parameters
item
[Type & Equatable & Codable] index
the index to move the item
Return Value
Elements
-
Delete an item
Declaration
Swift
public func delete(_ item: Element)
Parameters
item
the item to delete
Return Value
Elements
-
Get the index of an item.
Declaration
Swift
public func index(of item: Element) -> Int?
Parameters
item
the item to search for in the collection
Return Value
the item index
-
Checking if objects contain an item.
Declaration
Swift
public func contains(_ item: Element) -> Bool
Parameters
item
the item to check it it exists.
Return Value
if it exists
-
Save objects to file
Declaration
Swift
open func save(withFileName fileName: String? = nil, directory: Storage.Directory = .documents(customDirectory: nil)) throws
Parameters
fileName
The file name. If nil, default value String(describing: Elements
.self)` directory
The directory to save the file.
-
Returns objects from file if exists
Declaration
Swift
public static func loadFromFile(withFileName fileName: String? = nil, directory: Storage.Directory = .documents(customDirectory: nil)) -> Elements?
Parameters
fileName
The file name. If nil, default value String(describing: Elements
.self)` directory
The directory to save the file.