Skip to content

Instantly share code, notes, and snippets.

View eMdOS's full-sized avatar

Emilio Ojeda eMdOS

  • Zapopan, Jalisco
View GitHub Profile
@eMdOS
eMdOS / HowTo use xcconfig or plist with SPM.md
Created November 9, 2020 21:13 — forked from 4np/HowTo use xcconfig or plist with SPM.md
How to use a .xcconfig file and a .plist with a Swift Package Manager based project.

How to use a .xcconfig file and a .plist file with SPM

Worth a read for some more context.

Create a Package.xcconfig file

Create the file in the root of the project (where your Package.swift file lives as well), and use the following contents:

/// Package.xcconfig
let elements: [String] = ["A", "B", "C", "D", "E", "F", "G", "H", "I"]
let chunk_1 = elements[...2].joined()
let chunk_2 = elements[3...5].joined()
let chunk_3 = elements[6...].joined()
concat(elements) == chunk_1 <> chunk_2 <> chunk_3
concat(elements) == concat([chunk_1, chunk_2, chunk_3])
concat(["A", "B", "C"]) == [String](arrayLiteral: "A", "B", "C").reduce("", <>)
public func concat<M: Monoid>(_ elements: [M]) -> M {
elements.reduce(.empty, <>)
}
extension String: Monoid {
public static let empty: String = ""
}
extension Array: Monoid {
public static var empty: Array { [] }
}
// left identity
[] + ["A"] // = ["A"]
// right identity
["A"] + [] // = ["A"]
// left identity
"" + "A" // = "A"
// right identity
"A" + "" // = "A"
public protocol Monoid: Semigroup {
static var empty: Self { get }
}
XCTAssert(
AssociativeLaw<String>.verify(a: "hello", b: " ", c: "world!")
)
public extension AssociativeLaw where Element: Semigroup {
///
/// It verifies if the set of elements are **associative** through Semigroup's composition (`<>`).
///
/// The `<>` operator is used to express associativity in an abstract way.
/// This is because elements can either be associative through *addition* (`+`) or through *multiplication* (`*`).
///
/// - Parameters:
/// - a: The first semigroup element
/// - b: The second semigroup element