-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntValue.swift
More file actions
46 lines (37 loc) · 930 Bytes
/
IntValue.swift
File metadata and controls
46 lines (37 loc) · 930 Bytes
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
40
41
42
43
44
45
46
//
// IntValue.swift
// ListBook
//
// Created by Vladylav Filippov on 29.06.2021.
//
import Foundation
@propertyWrapper struct IntValue {
private var _wrappedValue: Int = 0
var wrappedValue: Int {
get {
return _wrappedValue
} set {
_wrappedValue = newValue
}
}
init(wrappedValue: Int = 0) {
self.wrappedValue = wrappedValue
}
init() {
self.wrappedValue = 0
}
}
extension IntValue: Codable {
init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
if container.decodeNil() {
_wrappedValue = 0
} else {
_wrappedValue = try container.decode(Int.self)
}
}
func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(_wrappedValue)
}
}