EditValueView
Library that makes easy to display property edit screens for SwiftUI.
Demo
Array |
Dictionary |
 |
 |
Enum(CaseIterable) |
Enum(CaseIterable & RawRepresentable) |
 |
 |
Codable |
 |
Usage
SwiftUI
EditValueView(target, key: "name", keyPath: \Item.name)
.onUpdate { target, newValue in
// update
}
.validate { target, newValue -> Bool in
// input validation
}
UIKit
let vc = EditValueViewController(target, key: "name", keyPath: \Item.name)
vc.onUpdate = { target, newValue in
// update
}
vc.validate = { target, newValue -> Bool in
// input validation
}
Protocol
If you use a keypath of an optional type, either define a default value according to the DefaultRepresentable
protocol or give the default value in the initilalize
struct Item: Codable {
var name: String
var date: Date
}
struct Message: Codable {
var content: String
var item: Item?
}
// Confirm to `DefaultRepresentable` protocol
extension Item: DefaultRepresentable {
static var defaultValue: Self {
.init(name: "name", date: Date())
}
}
// give default value
EditValueView(target, key: "item", keyPath: \Message.item, defaultValue: .init(name: "name", date: Date()))
EditValueView
Library that makes easy to display property edit screens for SwiftUI.
Demo
Usage
SwiftUI
UIKit
Protocol
If you use a keypath of an optional type, either define a default value according to the
DefaultRepresentable
protocol or give the default value in the initilalize