Updated the Repository model in the app target to implement some transient properties and conform to the Identifiable protocol.
This commit is contained in:
parent
58ac646e25
commit
2f8e3a094d
@ -15,24 +15,34 @@ final class Repository {
|
||||
// MARK: Properties
|
||||
|
||||
@Attribute(.unique) var path: URL
|
||||
|
||||
|
||||
var addedAt: Date
|
||||
var sortOrder: Int
|
||||
var active: Bool
|
||||
|
||||
// MARK: Initialisers
|
||||
|
||||
init(
|
||||
_ path: URL,
|
||||
sortOrder: Int,
|
||||
active: Bool = true,
|
||||
addedAt: Date = .now
|
||||
) {
|
||||
self.path = path
|
||||
self.addedAt = addedAt
|
||||
self.sortOrder = sortOrder
|
||||
self.active = active
|
||||
}
|
||||
|
||||
// MARK: Computed
|
||||
|
||||
@Transient var name: String { path.lastPathComponent }
|
||||
@Transient var folder: String {
|
||||
path.deletingLastPathComponent().relativePath
|
||||
}
|
||||
|
||||
@Transient var name: String {
|
||||
path.lastPathComponent
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Identifiable
|
||||
|
||||
extension Repository: Identifiable {}
|
||||
|
@ -18,18 +18,16 @@ extension Repository {
|
||||
let context = container.mainContext
|
||||
|
||||
context.insert(Repository(
|
||||
URL(filePath: "/full/path/to/repository/name-0.git"),
|
||||
sortOrder: 0
|
||||
URL(filePath: "/full/path/to/repository/name-0.git")
|
||||
))
|
||||
|
||||
context.insert(Repository(
|
||||
URL(filePath: "/full/path/to/repository/name-1.git"),
|
||||
sortOrder: 1
|
||||
active: false
|
||||
))
|
||||
|
||||
context.insert(Repository(
|
||||
URL(filePath: "/full/path/to/repository/name-2.git"),
|
||||
sortOrder: 2
|
||||
URL(filePath: "/full/path/to/repository/name-2.git")
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -62,24 +62,15 @@ struct ItemLabelStyle: LabelStyle {
|
||||
|
||||
#Preview("List Item component") {
|
||||
List {
|
||||
ListItem(
|
||||
repository: .init(
|
||||
.init(filePath: "/full/path/to/repository/name.git")!,
|
||||
sortOrder: 0
|
||||
)
|
||||
)
|
||||
ListItem(
|
||||
repository: .init(
|
||||
.init(filePath: "/full/path/to/repository/name.git")!,
|
||||
sortOrder: 0
|
||||
)
|
||||
)
|
||||
ListItem(
|
||||
repository: .init(
|
||||
.init(filePath: "/full/path/to/repository/name.git")!,
|
||||
sortOrder: 0
|
||||
)
|
||||
)
|
||||
ListItem(repository: .init(
|
||||
.init(filePath: "/full/path/to/repository/name.git")!
|
||||
))
|
||||
ListItem(repository: .init(
|
||||
.init(filePath: "/full/path/to/repository/name.git")!
|
||||
))
|
||||
ListItem(repository: .init(
|
||||
.init(filePath: "/full/path/to/repository/name.git")!
|
||||
))
|
||||
}
|
||||
.frame(width: 400, height: 220)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user