A Swift macro that generates a mutable, all-optional Draft companion for a value type. Fill it in incrementally, then call validated() to get the complete value back once every required field is set.
import Draftable
@Draftable
struct User: Equatable {
var id: Int
var name: String
var email: String?
var roles: [String] = []
}
var draft = User.Draft()
draft.name = "Ada"
draft.validated() // nil, id is still missing
draft.id = 42
draft.validated() // User(id: 42, name: "Ada", email: nil, roles: [])@Draftable adds a nested Draft where required (non-optional, no default) properties become optional, while optional and defaulted properties are carried through unchanged. validated() returns nil until every required field is present, then rebuilds the value through its memberwise initializer. It applies to structs only.
dependencies: [
.package(url: "https://github.com/ramikay/swift-draftable-macro.git", from: "1.0.0"),
]Then add Draftable to your target's dependencies.
Swift 6.0+ (Xcode 16+).