Last active
September 14, 2018 14:47
-
-
Save farzadshbfn/9fe89e79a12f657ed88725f3b61c935b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct CellNumber: Codable { | |
let digits: String | |
init(from decoder: Decoder) throws { | |
let container = try decoder.singleValueContainer() | |
let rawDigits = try container.decode(String.self) | |
// validate rawDigits by some Regex maybe? and throw appropriate errors? | |
// or extract CountryCode and AreaCode and save them in another way? | |
digits = rawDigits | |
} | |
func encode(to encoder: Encoder) throws { | |
var container = encoder.singleValueContainer() | |
try container.encode(digits) | |
} | |
} | |
struct Email: Codable { | |
let address: String | |
init(from decoder: Decoder) throws { | |
let container = try decoder.singleValueContainer() | |
let rawAddress = try container.decode(String.self) | |
// validate rawAddress by some Regex maybe? and throw appropriate errors? | |
address = rawAddress | |
} | |
func encode(to encoder: Encoder) throws { | |
var container = encoder.singleValueContainer() | |
try container.encode(address) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment