Skip to content

Instantly share code, notes, and snippets.

@odrobnik
Created October 21, 2016 14: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 odrobnik/c6681587dd210b5ffe327babe51e2618 to your computer and use it in GitHub Desktop.
Save odrobnik/c6681587dd210b5ffe327babe51e2618 to your computer and use it in GitHub Desktop.
func ~= <T>(lhs: inout T?, object: Any?)
{
lhs = object as? T
}
func ~= (lhs: inout URL?, object: Any?)
{
if let string = object as? String
{
lhs = URL(string: string)
}
else
{
lhs ~= object
}
}
func ~= (lhs: inout Date?, object: Any?)
{
if let timestamp = object as? Int
{
lhs = Date(timeIntervalSince1970: TimeInterval(timestamp/1000))
}
else
{
lhs ~= object
}
}
startDate ~= dictionary["startTimestamp"]
endDate ~= dictionary["endTimestamp"]
clientName ~= dictionary["clientName"]
providerName ~= dictionary["providerName"]
roomID ~= dictionary["roomId"]
productPictureURL ~= dictionary["productPictureUrl"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment