56 lines
1.1 KiB
Swift
56 lines
1.1 KiB
Swift
import Foundation
|
|
import SwiftUI
|
|
|
|
final class LocalizedPost: ObservableObject {
|
|
|
|
@Published
|
|
var title: String
|
|
|
|
@Published
|
|
var content: String
|
|
|
|
@Published
|
|
var lastModified: Date?
|
|
|
|
@Published
|
|
var images: [ImageResource]
|
|
|
|
init(title: String? = nil,
|
|
content: String,
|
|
lastModified: Date? = nil,
|
|
images: [ImageResource] = []) {
|
|
self.title = title ?? ""
|
|
self.content = content
|
|
self.lastModified = lastModified
|
|
self.images = images
|
|
}
|
|
|
|
var displayImages: [Image] {
|
|
images.map { $0.imageToDisplay }
|
|
}
|
|
|
|
@MainActor
|
|
func editableTitle() -> Binding<String> {
|
|
Binding(
|
|
get: {
|
|
self.title
|
|
},
|
|
set: { newValue in
|
|
self.title = newValue
|
|
}
|
|
)
|
|
}
|
|
|
|
@MainActor
|
|
func editableContent() -> Binding<String> {
|
|
Binding(
|
|
get: {
|
|
self.content
|
|
},
|
|
set: { newValue in
|
|
self.content = newValue
|
|
}
|
|
)
|
|
}
|
|
}
|