Skip to content

Commit 51ab9b4

Browse files
authored
Merge pull request #2 from lukepistrol/main
added static properties for type-safe access of custom symbols
2 parents fe91b1e + 23956f4 commit 51ab9b4

File tree

10 files changed

+38
-17
lines changed

10 files changed

+38
-17
lines changed

Sources/CodeEditSymbols/CodeEditSymbols.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,36 @@ import SwiftUI
88

99
public extension Image {
1010

11+
/// Creates an Image representing a custom SF Symbol
12+
/// - Parameter symbol: The name of the symbol in `Symbols.xcassets`
1113
init(symbol: String) {
1214
self.init(symbol, bundle: Bundle.module)
1315
}
1416

17+
// MARK: - Symbols
18+
19+
static let vault: Image = .init(symbol: "vault")
20+
static let vault_fill: Image = .init(symbol: "vault.fill")
21+
static let commit: Image = .init(symbol: "commit")
22+
static let checkout: Image = .init(symbol: "checkout")
23+
1524
}
1625

1726

1827
public extension NSImage {
1928

29+
/// Returns a NSImage representing a custom SF Symbol
30+
/// - Parameter named: The name of the symbol in `Symbols.xcassets`
31+
/// - Returns: a NSImage
2032
static func symbol(named: String) -> NSImage {
2133
Bundle.module.image(forResource: named) ?? .init()
2234
}
2335

36+
// MARK: - Symbols
37+
38+
static let vault: NSImage = .symbol(named: "vault")
39+
static let vault_fill: NSImage = .symbol(named: "vault.fill")
40+
static let commit: NSImage = .symbol(named: "commit")
41+
static let checkout: NSImage = .symbol(named: "checkout")
42+
2443
}

Tests/CodeEditSymbolsTests/CodeEditSymbolsTests.swift

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,63 +9,65 @@ final class CodeEditSymbolsTests: XCTestCase {
99

1010
// MARK: VAULT
1111

12+
private let record: Bool = false
13+
1214
func testCreateNSImageVault() {
13-
let image = NSImage.symbol(named: "vault")
15+
let image = NSImage.vault
1416
let view = NSImageView(image: image)
15-
assertSnapshot(matching: view, as: .image)
17+
assertSnapshot(matching: view, as: .image, record: record)
1618
}
1719

1820
func testCreateNSImageVaultFill() {
19-
let image = NSImage.symbol(named: "vault.fill")
21+
let image = NSImage.vault_fill
2022
let view = NSImageView(image: image)
21-
assertSnapshot(matching: view, as: .image)
23+
assertSnapshot(matching: view, as: .image, record: record)
2224
}
2325

2426
// MARK: COMMIT
2527

2628
func testCreateNSImageCommit() {
27-
let image = NSImage.symbol(named: "commit")
29+
let image = NSImage.commit
2830
let view = NSImageView(image: image)
29-
assertSnapshot(matching: view, as: .image)
31+
assertSnapshot(matching: view, as: .image, record: record)
3032
}
3133

3234
// MARK: CHECKOUT
3335

3436
func testCreateNSImageCheckout() {
35-
let image = Image(symbol: "checkout")
36-
let view: NSView = NSHostingController(rootView: image).view
37-
assertSnapshot(matching: view, as: .image(size: view.intrinsicContentSize))
37+
let image = NSImage.checkout
38+
let view: NSView = NSImageView(image: image)
39+
assertSnapshot(matching: view, as: .image, record: record)
3840
}
3941

4042
// MARK: - Image Tests
4143

4244
// MARK: VAULT
4345

4446
func testCreateImageVault() {
45-
let image = Image(symbol: "vault")
47+
let image = Image.vault
4648
let view: NSView = NSHostingController(rootView: image).view
47-
assertSnapshot(matching: view, as: .image(size: view.intrinsicContentSize))
49+
assertSnapshot(matching: view, as: .image(size: view.intrinsicContentSize), record: record)
4850
}
4951

5052
func testCreateImageVaultFill() {
51-
let image = Image(symbol: "vault.fill")
53+
let image = Image.vault_fill
5254
let view: NSView = NSHostingController(rootView: image).view
53-
assertSnapshot(matching: view, as: .image(size: view.intrinsicContentSize))
55+
assertSnapshot(matching: view, as: .image(size: view.intrinsicContentSize), record: record)
5456
}
5557

5658
// MARK: COMMIT
5759

5860
func testCreateImageCommit() {
59-
let image = Image(symbol: "commit")
61+
let image = Image.commit
6062
let view: NSView = NSHostingController(rootView: image).view
61-
assertSnapshot(matching: view, as: .image(size: view.intrinsicContentSize))
63+
assertSnapshot(matching: view, as: .image(size: view.intrinsicContentSize), record: record)
6264
}
6365

6466
// MARK: CHECKOUT
6567

6668
func testCreateImageCheckout() {
67-
let image = Image(symbol: "checkout")
69+
let image = Image.checkout
6870
let view: NSView = NSHostingController(rootView: image).view
69-
assertSnapshot(matching: view, as: .image(size: view.intrinsicContentSize))
71+
assertSnapshot(matching: view, as: .image(size: view.intrinsicContentSize), record: record)
7072
}
7173
}
-46 Bytes
Loading
-32 Bytes
Loading
-36 Bytes
Loading
-14 Bytes
Loading
-174 Bytes
Loading
-24 Bytes
Loading
-52 Bytes
Loading
-38 Bytes
Loading

0 commit comments

Comments
 (0)