Skip to content

Instantly share code, notes, and snippets.

@mayoff mayoff/FormatOptions.swift
Last active Feb 10, 2017

Embed
What would you like to do?
Avoiding duplication of property names
// For https://twitter.com/nicklockwood/status/819938181483233285
protocol Withable {
init()
}
extension Withable {
func with(_ body: (inout Self) -> ()) -> Self {
var copy = self
body(&copy)
return copy
}
init(_ body: (inout Self) -> ()) {
self.init()
body(&self)
}
}
public enum WrapMode { case disabled, beforeFirst }
public enum IndentMode { case indent }
public struct FormatOptions {
public var indent = " "
public var linebreak = "\n"
public var allowInlineSemicolons = true
public var spaceAroundRangeOperators = true
public var useVoid = true
public var trailingCommas = true
public var trailingClosures = false
public var indentComments = true
public var truncateBlankLines = true
public var insertBlankLines = true
public var removeBlankLines = true
public var allmanBraces = false
public var stripHeader = false
public var ifdefIndent = IndentMode.indent
public var wrapArguments = WrapMode.disabled
public var wrapElements = WrapMode.beforeFirst
public var uppercaseHex = true
public var experimentalRules = false
public var fragment = false
}
extension FormatOptions: Withable { }
let options1 = FormatOptions { $0.fragment = true; $0.wrapArguments = .beforeFirst }
let options2 = options1.with({ $0.uppercaseHex = false; $0.trailingCommas = false })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.