Skip to content

Instantly share code, notes, and snippets.

@stevencurtis
Last active July 6, 2020 08:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevencurtis/a85e78e35b8fcf7545cf60ff26936ae3 to your computer and use it in GitHub Desktop.
Save stevencurtis/a85e78e35b8fcf7545cf60ff26936ae3 to your computer and use it in GitHub Desktop.
isopropertywrapper
@propertyWrapper
struct ISO8601DateFormatted {
static private let formatter = ISO8601DateFormatter()
var projectedValue: String { ISO8601DateFormatted.formatter.string(from: wrappedValue) }
var wrappedValue: Date
}
struct Form {
@ISO8601DateFormatted var createdAt: Date
}
let user = Form(createdAt: Date())
user.createdAt // "Jul 6, 2020 at 8:56 AM"
user.$createdAt // "2020-07-06 07:56:24 +0000\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment