-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathButtonStateBuilder.swift
32 lines (25 loc) · 1.08 KB
/
ButtonStateBuilder.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
//
// ButtonStateBuilder.swift
// Eject
//
// Created by Brian King on 10/19/16.
// Copyright © 2016 Brian King. All rights reserved.
//
import Foundation
struct ButtonStateBuilder: Builder {
func buildElement(attributes: inout [String: String], document: XIBDocument, parent: Reference?) throws -> Reference? {
guard let parent = parent else { throw XIBParser.Error.needParent }
let state = try attributes.removeRequiredValue(forKey: "key")
document.containerContext = .setter(suffix: "for: \(ValueFormat.enumeration.transform(string: state))")
let attributeFormat: [(String, ValueFormat)] = [("title", .string), ("image", .image), ("backgroundImage", .image)]
for (key, format) in attributeFormat {
if let value = attributes.removeValue(forKey: key) {
try document.addVariableConfiguration(for: parent.identifier, attribute: key, value: BasicValue(value: value, format: format))
}
}
return parent
}
func complete(document: XIBDocument) {
document.containerContext = nil
}
}