forked from CoreOffice/XMLCoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
KeyedBox.swift
55 lines (46 loc) · 1.21 KB
/
KeyedBox.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// KeyedBox.swift
// XMLCoder
//
// Created by Vincent Esche on 11/19/18.
//
struct KeyedBox {
typealias Key = String
typealias Attribute = SimpleBox
typealias Element = Box
typealias Attributes = KeyedStorage<Key, Attribute>
typealias Elements = KeyedStorage<Key, Element>
var elements = Elements()
var attributes = Attributes()
var unboxed: (elements: Elements, attributes: Attributes) {
return (
elements: elements,
attributes: attributes
)
}
var value: SimpleBox? {
return elements[""].first as? SimpleBox
}
}
extension KeyedBox {
init<E, A>(elements: E, attributes: A)
where E: Sequence, E.Element == (Key, Element),
A: Sequence, A.Element == (Key, Attribute) {
let elements = Elements(elements)
let attributes = Attributes(attributes)
self.init(elements: elements, attributes: attributes)
}
}
extension KeyedBox: Box {
var isNull: Bool {
return false
}
var xmlString: String? {
return nil
}
}
extension KeyedBox: CustomStringConvertible {
var description: String {
return "{attributes: \(attributes), elements: \(elements)}"
}
}