Skip to content

Commit e360af4

Browse files
committed
Gardening, add convenience init for supporting variable values and test fixes.
1 parent f721bfe commit e360af4

File tree

6 files changed

+123
-40
lines changed

6 files changed

+123
-40
lines changed

SFSymbol.xcodeproj/project.pbxproj

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@
2424
4ECFE97624F1598100D672A6 /* SFSymbol2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4ECFE97224F1598100D672A6 /* SFSymbol2.swift */; };
2525
E14A2A1B28FEFFA700E07E33 /* SFSymbol4.swift in Sources */ = {isa = PBXBuildFile; fileRef = E14A2A1A28FEFFA700E07E33 /* SFSymbol4.swift */; };
2626
E14A2A2228FF05E200E07E33 /* SFSymbol3.swift in Sources */ = {isa = PBXBuildFile; fileRef = E14A2A2128FF05E200E07E33 /* SFSymbol3.swift */; };
27-
E19872FF290EACE000DE0371 /* Image+SFSymbol.swift in Sources */ = {isa = PBXBuildFile; fileRef = E19872FE290EACE000DE0371 /* Image+SFSymbol.swift */; };
28-
E1987301290EAD9D00DE0371 /* UIImage+SFSymbol.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1987300290EAD9D00DE0371 /* UIImage+SFSymbol.swift */; };
27+
E1546154298FEA770016DACC /* UIImage+SFSymbol.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1546151298FEA770016DACC /* UIImage+SFSymbol.swift */; };
28+
E1546155298FEA770016DACC /* Image+SFSymbol.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1546152298FEA770016DACC /* Image+SFSymbol.swift */; };
29+
E1546156298FEA770016DACC /* NSImage+SFSymbol.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1546153298FEA770016DACC /* NSImage+SFSymbol.swift */; };
30+
E1CE21BD298F9556008E54B8 /* ImageExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1CE21BC298F9556008E54B8 /* ImageExtensionTests.swift */; };
31+
E1CE21BF298F9619008E54B8 /* UIImageExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1CE21BE298F9619008E54B8 /* UIImageExtensionTests.swift */; };
2932
OBJ_27 /* SFSymbol.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_9 /* SFSymbol.swift */; };
3033
OBJ_34 /* Package.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_6 /* Package.swift */; };
3134
OBJ_48 /* SFSymbol.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = "SFSymbol::SFSymbol::Product" /* SFSymbol.framework */; };
@@ -54,8 +57,11 @@
5457
4ECFE97224F1598100D672A6 /* SFSymbol2.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SFSymbol2.swift; sourceTree = "<group>"; };
5558
E14A2A1A28FEFFA700E07E33 /* SFSymbol4.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SFSymbol4.swift; sourceTree = "<group>"; };
5659
E14A2A2128FF05E200E07E33 /* SFSymbol3.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SFSymbol3.swift; sourceTree = "<group>"; };
57-
E19872FE290EACE000DE0371 /* Image+SFSymbol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Image+SFSymbol.swift"; sourceTree = "<group>"; };
58-
E1987300290EAD9D00DE0371 /* UIImage+SFSymbol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImage+SFSymbol.swift"; sourceTree = "<group>"; };
60+
E1546151298FEA770016DACC /* UIImage+SFSymbol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "UIImage+SFSymbol.swift"; path = "Sources/Extensions/UIImage+SFSymbol.swift"; sourceTree = "<group>"; };
61+
E1546152298FEA770016DACC /* Image+SFSymbol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "Image+SFSymbol.swift"; path = "Sources/Extensions/Image+SFSymbol.swift"; sourceTree = "<group>"; };
62+
E1546153298FEA770016DACC /* NSImage+SFSymbol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "NSImage+SFSymbol.swift"; path = "Sources/Extensions/NSImage+SFSymbol.swift"; sourceTree = "<group>"; };
63+
E1CE21BC298F9556008E54B8 /* ImageExtensionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ImageExtensionTests.swift; path = Tests/SFSymbolTests/ImageExtensionTests.swift; sourceTree = "<group>"; };
64+
E1CE21BE298F9619008E54B8 /* UIImageExtensionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIImageExtensionTests.swift; sourceTree = "<group>"; };
5965
OBJ_19 /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
6066
OBJ_20 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
6167
OBJ_21 /* SFSymbol.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; path = SFSymbol.podspec; sourceTree = "<group>"; };
@@ -116,31 +122,25 @@
116122
path = SFSymbol4;
117123
sourceTree = "<group>";
118124
};
119-
E19872FD290EACA500DE0371 /* Extensions */ = {
125+
E1546150298FEA400016DACC /* Extensions */ = {
120126
isa = PBXGroup;
121127
children = (
122-
E19872FE290EACE000DE0371 /* Image+SFSymbol.swift */,
123-
E1987300290EAD9D00DE0371 /* UIImage+SFSymbol.swift */,
128+
E1546152298FEA770016DACC /* Image+SFSymbol.swift */,
129+
E1546153298FEA770016DACC /* NSImage+SFSymbol.swift */,
130+
E1546151298FEA770016DACC /* UIImage+SFSymbol.swift */,
124131
);
125-
path = Extensions;
132+
name = Extensions;
126133
sourceTree = "<group>";
127134
};
128135
OBJ_10 /* Tests */ = {
129136
isa = PBXGroup;
130137
children = (
131-
OBJ_11 /* SFSymbolTests */,
138+
E1CE21BC298F9556008E54B8 /* ImageExtensionTests.swift */,
139+
E1CE21BE298F9619008E54B8 /* UIImageExtensionTests.swift */,
132140
);
133141
name = Tests;
134142
sourceTree = SOURCE_ROOT;
135143
};
136-
OBJ_11 /* SFSymbolTests */ = {
137-
isa = PBXGroup;
138-
children = (
139-
);
140-
name = SFSymbolTests;
141-
path = Tests/SFSymbolTests;
142-
sourceTree = SOURCE_ROOT;
143-
};
144144
OBJ_14 /* Products */ = {
145145
isa = PBXGroup;
146146
children = (
@@ -168,7 +168,7 @@
168168
OBJ_7 /* Sources */ = {
169169
isa = PBXGroup;
170170
children = (
171-
E19872FD290EACA500DE0371 /* Extensions */,
171+
E1546150298FEA400016DACC /* Extensions */,
172172
OBJ_8 /* SFSymbol */,
173173
);
174174
name = Sources;
@@ -244,6 +244,14 @@
244244
attributes = {
245245
LastSwiftMigration = 9999;
246246
LastUpgradeCheck = 1200;
247+
TargetAttributes = {
248+
"SFSymbol::SFSymbolPackageTests::ProductTarget" = {
249+
LastSwiftMigration = 1420;
250+
};
251+
"SFSymbol::SFSymbolTests" = {
252+
LastSwiftMigration = 1420;
253+
};
254+
};
247255
};
248256
buildConfigurationList = OBJ_2 /* Build configuration list for PBXProject "SFSymbol" */;
249257
compatibilityVersion = "Xcode 3.2";
@@ -272,11 +280,12 @@
272280
buildActionMask = 0;
273281
files = (
274282
E14A2A1B28FEFFA700E07E33 /* SFSymbol4.swift in Sources */,
283+
E1546156298FEA770016DACC /* NSImage+SFSymbol.swift in Sources */,
275284
4ECFE97624F1598100D672A6 /* SFSymbol2.swift in Sources */,
276-
E19872FF290EACE000DE0371 /* Image+SFSymbol.swift in Sources */,
285+
E1546155298FEA770016DACC /* Image+SFSymbol.swift in Sources */,
277286
OBJ_27 /* SFSymbol.swift in Sources */,
278-
E1987301290EAD9D00DE0371 /* UIImage+SFSymbol.swift in Sources */,
279287
E14A2A2228FF05E200E07E33 /* SFSymbol3.swift in Sources */,
288+
E1546154298FEA770016DACC /* UIImage+SFSymbol.swift in Sources */,
280289
);
281290
runOnlyForDeploymentPostprocessing = 0;
282291
};
@@ -292,6 +301,8 @@
292301
isa = PBXSourcesBuildPhase;
293302
buildActionMask = 0;
294303
files = (
304+
E1CE21BF298F9619008E54B8 /* UIImageExtensionTests.swift in Sources */,
305+
E1CE21BD298F9556008E54B8 /* ImageExtensionTests.swift in Sources */,
295306
);
296307
runOnlyForDeploymentPostprocessing = 0;
297308
};
@@ -442,12 +453,19 @@
442453
OBJ_37 /* Debug */ = {
443454
isa = XCBuildConfiguration;
444455
buildSettings = {
456+
CLANG_ENABLE_MODULES = YES;
457+
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
458+
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
459+
SWIFT_VERSION = 5.0;
445460
};
446461
name = Debug;
447462
};
448463
OBJ_38 /* Release */ = {
449464
isa = XCBuildConfiguration;
450465
buildSettings = {
466+
CLANG_ENABLE_MODULES = YES;
467+
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
468+
SWIFT_VERSION = 5.0;
451469
};
452470
name = Release;
453471
};
@@ -512,13 +530,14 @@
512530
);
513531
HEADER_SEARCH_PATHS = "$(inherited)";
514532
INFOPLIST_FILE = SFSymbol.xcodeproj/SFSymbolTests_Info.plist;
515-
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
533+
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
516534
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @loader_path/../Frameworks @loader_path/Frameworks";
517535
MACOSX_DEPLOYMENT_TARGET = 10.15;
518536
OTHER_CFLAGS = "$(inherited)";
519537
OTHER_LDFLAGS = "$(inherited)";
520538
OTHER_SWIFT_FLAGS = "$(inherited)";
521539
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited)";
540+
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
522541
SWIFT_VERSION = 5.0;
523542
TARGET_NAME = SFSymbolTests;
524543
TVOS_DEPLOYMENT_TARGET = 13.0;
@@ -537,7 +556,7 @@
537556
);
538557
HEADER_SEARCH_PATHS = "$(inherited)";
539558
INFOPLIST_FILE = SFSymbol.xcodeproj/SFSymbolTests_Info.plist;
540-
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
559+
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
541560
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @loader_path/../Frameworks @loader_path/Frameworks";
542561
MACOSX_DEPLOYMENT_TARGET = 10.15;
543562
OTHER_CFLAGS = "$(inherited)";
Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,18 @@
2222

2323
import SwiftUI
2424

25-
@available(macOS 11, *)
26-
@available(iOS 13, *)
27-
public extension Image {
25+
@available(iOS 13, macOS 15, *)
26+
extension Image {
2827
/// Create Image from SFSymbol
29-
init<T: RawRepresentable>(symbol: T) where T.RawValue == String {
28+
public init<T: RawRepresentable>(symbol: T) where T.RawValue == String {
3029
self.init(systemName: symbol.rawValue)
3130
}
3231
}
32+
33+
@available(iOS 16, macOS 15, *)
34+
extension Image {
35+
/// Create Image from SFSymbol with optional `variableValue`
36+
public init<T: RawRepresentable>(symbol: T, variableValue: Double? = nil) where T.RawValue == String {
37+
self.init(systemName: symbol.rawValue, variableValue: variableValue)
38+
}
39+
}
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,8 @@
2424
import Cocoa
2525

2626
@available(macOS 11, *)
27-
public extension NSImage {
28-
convenience init?(symbol: SFSymbol, accessibilityDescription description: String? = nil) {
29-
self.init(systemSymbolName: symbol.rawValue, accessibilityDescription: description)
30-
}
31-
32-
convenience init?(symbol: SFSymbol2, accessibilityDescription description: String? = nil) {
27+
extension NSImage {
28+
public convenience init?<T: RawRepresentable>(symbol: T, accessibilityDescription description: String? = nil) where T.RawValue == String {
3329
self.init(systemSymbolName: symbol.rawValue, accessibilityDescription: description)
3430
}
3531
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
import UIKit
2525

2626
@available(iOS 13.0, *)
27-
public extension UIImage {
28-
convenience init?<T: RawRepresentable>(symbol: T) where T.RawValue == String {
27+
extension UIImage {
28+
public convenience init?<T: RawRepresentable>(symbol: T) where T.RawValue == String {
2929
self.init(systemName: symbol.rawValue)
3030
}
3131

32-
convenience init?<T: RawRepresentable>(symbol: T, with configuration: Configuration) where T.RawValue == String {
32+
public convenience init?<T: RawRepresentable>(symbol: T, with configuration: Configuration) where T.RawValue == String {
3333
self.init(systemName: symbol.rawValue, withConfiguration: configuration)
3434
}
3535
}
Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,43 @@
11
//
2-
// Image+Tests.swift
2+
// UIImage+SFSymbol.swift
33
// SFSymbol
44
//
5-
// Created by Nicholas Maccharoli on 2020/07/16.
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
611
//
12+
// The above copyright notice and this permission notice shall be included in
13+
// all copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
// THE SOFTWARE.
722

823
@testable import SFSymbol
924
import SwiftUI
1025
import XCTest
1126

12-
@available(macOS 11, *)
1327
class ImageExtensionTests: XCTestCase {
1428
func testImagefromSFSymbol() {
15-
let imageFromSFSymbol = Image(symbol: .aSquare)
16-
let imageFromSymbolString = Image(systemName: SFSymbol.aSquare.rawValue)
29+
let imageFromSFSymbol = Image(symbol: SFSymbol4.infinity)
30+
let imageFromSymbolString = Image(systemName: SFSymbol4.infinity.rawValue)
1731

1832
XCTAssert(imageFromSFSymbol == imageFromSymbolString, "Image(symbol:) is broken")
1933
}
2034
}
35+
36+
extension ImageExtensionTests {
37+
func testImageVariableValuesConvenienceInit() {
38+
let imageFromSFSymbol = Image(symbol: SFSymbol4.wifi, variableValue: 0.5)
39+
let imageFromSymbolString = Image(systemName: SFSymbol4.infinity.rawValue)
40+
41+
XCTAssert(imageFromSFSymbol != imageFromSymbolString, "Image(symbol:) is broken")
42+
}
43+
}

UIImageExtensionTests.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// UIImage+SFSymbol.swift
3+
// SFSymbol
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in
13+
// all copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
// THE SOFTWARE.
22+
23+
@testable import SFSymbol
24+
import UIKit
25+
import XCTest
26+
27+
@available(iOS 13, macOS 11, *)
28+
class UIImageExtensionTests: XCTestCase {
29+
func testUIImageInitilizer() {
30+
let expected = UIImage(systemName: SFSymbol4.infinity.rawValue)
31+
let result = UIImage(symbol: SFSymbol4.infinity)
32+
33+
XCTAssertNotNil(expected)
34+
XCTAssertNotNil(result)
35+
XCTAssert(expected == result)
36+
}
37+
}
38+

0 commit comments

Comments
 (0)