-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathOutletBuilder.swift
40 lines (35 loc) · 1.55 KB
/
OutletBuilder.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
//
// OutletBuilder.swift
// Eject
//
// Created by Brian King on 10/19/16.
// Copyright © 2016 Brian King. All rights reserved.
//
import Foundation
struct OutletBuilder: Builder {
let collection: Bool
var setterStyle: AssociationContext {
return collection ? .append : .assignment
}
func buildElement(attributes: inout [String: String], document: XIBDocument, parent: Reference?) throws -> Reference? {
guard let parent = parent else { throw XIBParser.Error.needParent }
let property = try attributes.removeRequiredValue(forKey: "property")
let destination = try attributes.removeRequiredValue(forKey: "destination")
attributes.removeValue(forKey: "id")
attributes.removeValue(forKey: "appends")
let value = VariableValue(objectIdentifier: destination)
try document.addVariableConfiguration(
for: parent.identifier,
attribute: property,
value: value,
context: setterStyle
)
// Specify the outlet name as a variable name override. This rule is ignored for `view` because it's in most view controller .xib's,
// and the class-inferred name is almost always better than 'view'. Also, if the outlet is to a collection, do not use it, it will look
// wrong and probably have a duplication.
if document.variableNameOverrides[destination] == nil && property != "view" && collection == false {
document.variableNameOverrides[destination] = { _ in property }
}
return parent
}
}