-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathNumber.swift
39 lines (35 loc) · 1004 Bytes
/
Number.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//
// Number.swift
// hhfa
//
// Created by hhfa on 11/01/2018.
// Copyright © 2018 hhfa. All rights reserved.
//
import UIKit
struct Number:Decodable {
var intValue:Int
var stringValue:String
init(from decoder: Decoder) throws {
let singleValueContainer = try decoder.singleValueContainer()
if let stringValue = try? singleValueContainer.decode(String.self)
{
if let intValue = Int(stringValue)
{
self.intValue = intValue
self.stringValue = String(intValue);
} else
{
self.intValue = 0
self.stringValue = String(0);
}
} else if let stringValue = try? singleValueContainer.decode(Int.self)
{
self.intValue = stringValue
self.stringValue = String(stringValue);
} else
{
self.intValue = 0
self.stringValue = String(0);
}
}
}