-
Notifications
You must be signed in to change notification settings - Fork 3
Transformations
Brian Mullen edited this page Dec 4, 2016
·
2 revisions
What if you don't like how Outlaw implements the default value extraction? Or you have an edge case for extraction?
No problem! All you need is a transformation function when extracting the values. Outlaw will extract the raw value for you and supply it to your transformation function.
let formatter = DateFormatter()
formatter.timeZone = TimeZone(abbreviation: "GMT")
formatter.dateFormat = "MM/dd/yyyy"
let date: Date? = json.value(for: "date", with: { (rawValue: String) -> Date? in
return formatter.date(from: rawValue)
})We can also use the power of swift and simplify the above code to:
let date: Date? = json.value(for: "date", with: formatter.date)