28 lines
819 B
Swift
28 lines
819 B
Swift
import SwiftUI
|
|
import SwiftData
|
|
|
|
/// A protocol for entities that can be managed in a generic list view.
|
|
protocol EditableEntity: PersistentModel, Identifiable, Hashable {
|
|
/// The name of the entity to be displayed in the list.
|
|
var name: String { get set }
|
|
|
|
/// A view for adding or editing the entity.
|
|
associatedtype FormView: View
|
|
@ViewBuilder static func formView(for model: Self) -> FormView
|
|
|
|
/// Creates a new, empty instance of the entity.
|
|
static func createNew() -> Self
|
|
|
|
/// The title for the navigation bar in the list view.
|
|
static var navigationTitle: String { get }
|
|
|
|
/// An optional property to specify a count to be displayed in the list item.
|
|
var count: Int? { get }
|
|
}
|
|
|
|
extension EditableEntity {
|
|
var count: Int? {
|
|
return nil
|
|
}
|
|
}
|