Skip to content

Commit

Permalink
Merge pull request #48 from jaeilers/feature/update-example-swift-6
Browse files Browse the repository at this point in the history
feat: Update example project to Swift 6
  • Loading branch information
jaeilers authored Oct 5, 2024
2 parents 6c04ee1 + 312d130 commit bfcceb0
Show file tree
Hide file tree
Showing 12 changed files with 164 additions and 137 deletions.
2 changes: 1 addition & 1 deletion Example/Core/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.9
// swift-tools-version: 6.0

import PackageDescription

Expand Down
2 changes: 1 addition & 1 deletion Example/Core/Sources/Core/L10n.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

enum L10n {
enum L10n: Sendable {
static let condensedText = NSLocalizedString("condensed.text", bundle: Bundle.module, comment: "")
static let dummyTextGerman = NSLocalizedString("dummy.text.german", bundle: Bundle.module, comment: "")
static let monospacedText = NSLocalizedString("monospaced.text", bundle: Bundle.module, comment: "")
Expand Down
15 changes: 12 additions & 3 deletions Example/Core/Sources/Core/ListItem.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import Foundation

public struct ListItem: Hashable, Identifiable {
public struct ListItem: Hashable, Identifiable, Sendable {

public let text: NSAttributedString
// MainActor closure until `NSAttributedString` conforms to `Sendable` (hopefully)
public let text: @MainActor () -> NSAttributedString
public let id = UUID()

public init(text: NSAttributedString) {
public init(text: @MainActor @escaping () -> NSAttributedString) {
self.text = text
}

public static func == (lhs: Self, rhs: Self) -> Bool {
lhs.id == rhs.id
}

public func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
}
256 changes: 136 additions & 120 deletions Example/Core/Sources/Core/ListItemFactory.swift
Original file line number Diff line number Diff line change
@@ -1,134 +1,150 @@
import Foundation
import NSAttributedStringBuilder

public enum ListItemFactory {
public enum ListItemFactory: Sendable {

public static func makeListItems() -> [ListItem] {
[
ListItem(text: NSAttributedString {
#if !os(watchOS)
AImage.globe()
.image(systemName: "star.fill", bounds: .init(origin: .zero, size: .init(width: 100, height: 90)))
.image(.globe())
.foregroundColor(.coreOrange)
.alignment(.center)
.underline()

Newline()
#endif

"Hello,"
.alignment(.center)
.italic()
.bold()

Space()

"world!"
.foregroundColor(.coreRed)
.bold()
.strikethrough(color: .coreOrange)
.backgroundColor(.coreYellow)
}),
ListItem(text: NSAttributedString {
"Hello"
.italic()

Space()

"SwiftUI!"
.bold()
.foregroundColor(.corePurple)
}),
ListItem(text: L10n.monospacedText.foregroundColor(.coreBlue).monospaced()),
ListItem(text: NSAttributedString {
"Hello"
.foregroundColor(.coreOrange)
.underline()
.italic()
.kerning(1.5)

Space()

"World."
.foregroundColor(.coreRed)
.bold()
}),
ListItem(text: NSAttributedString {
let attributes = Attributes()
.font(.systemFont(ofSize: 16))
.italic()
.underline()

"Hello"
.addingAttributes(attributes)
.foregroundColor(.coreBlue)

Space()

"World"
.addingAttributes(attributes)
.foregroundColor(.coreTeal)

Space()

"again!"
.addingAttributes(attributes)
.foregroundColor(.coreGreen)
}),
ListItem(text: NSAttributedString {
L10n.pangramEnglish
.language(.english)
.font(.systemFont(ofSize: 30))
.stroke()
.foregroundColor(.coreTeal)
}),
ListItem(text: L10n.condensedText.condensed().alignment(.center)),
ListItem(text: NSAttributedString {
L10n.pangramGreek
.kerning(5.0)
.language(.greek)
}),
ListItem(text: NSAttributedString {
"ABCDEF".tracking(-3)
Newline()
"ABCDEF".tracking(0)
Newline()
"ABCDEF".tracking(3)
}),
ListItem(
text: L10n.dummyTextGerman
ListItem {
NSAttributedString {
#if !os(watchOS)
AImage.globe()
.image(systemName: "star.fill", bounds: .init(origin: .zero, size: .init(width: 100, height: 90)))
.image(.globe())
.foregroundColor(.coreOrange)
.alignment(.center)
.underline()

Newline()
#endif

"Hello,"
.alignment(.center)
.italic()
.bold()

Space()

"world!"
.foregroundColor(.coreRed)
.bold()
.strikethrough(color: .coreOrange)
.backgroundColor(.coreYellow)
}
},
ListItem {
NSAttributedString {
"Hello"
.italic()

Space()

"SwiftUI!"
.bold()
.foregroundColor(.corePurple)
}
},
ListItem { L10n.monospacedText.foregroundColor(.coreBlue).monospaced() },
ListItem {
NSAttributedString {
"Hello"
.foregroundColor(.coreOrange)
.underline()
.italic()
.kerning(1.5)

Space()

"World."
.foregroundColor(.coreRed)
.bold()
}
},
ListItem {
NSAttributedString {
let attributes = Attributes()
.font(.systemFont(ofSize: 16))
.italic()
.underline()

"Hello"
.addingAttributes(attributes)
.foregroundColor(.coreBlue)

Space()

"World"
.addingAttributes(attributes)
.foregroundColor(.coreTeal)

Space()

"again!"
.addingAttributes(attributes)
.foregroundColor(.coreGreen)
}
},
ListItem {
NSAttributedString {
L10n.pangramEnglish
.language(.english)
.font(.systemFont(ofSize: 30))
.stroke()
.foregroundColor(.coreTeal)
}
},
ListItem { L10n.condensedText.condensed().alignment(.center) },
ListItem {
NSAttributedString {
L10n.pangramGreek
.kerning(5.0)
.language(.greek)
}
},
ListItem {
NSAttributedString {
"ABCDEF".tracking(-3)
Newline()
"ABCDEF".tracking(0)
Newline()
"ABCDEF".tracking(3)
}
},
ListItem {
L10n.dummyTextGerman
.hyphenationFactor(1.0)
.language(.german)
.lineBreakMode(.byWordWrapping)
.lineBreakStrategy(.standard)
.font(.systemFont(ofSize: 20))
),
ListItem(text: NSAttributedString {
L10n.pangramEnglish
.writingDirection(.rightToLeftDirectionOverride)
.baseWritingDirection(.rightToLeft)

Newline()

""
.newline()
.text(L10n.pangramArabic)
.font(.systemFont(ofSize: 40))
.baseWritingDirection(.rightToLeft)
.language(.arabic)

Newline()

""
.font(.systemFont(ofSize: 40))
.baseWritingDirection(.leftToRight)

Newline()

L10n.pangramHebrew
.baseWritingDirection(.rightToLeft)
})
},
ListItem {
NSAttributedString {
L10n.pangramEnglish
.writingDirection(.rightToLeftDirectionOverride)
.baseWritingDirection(.rightToLeft)

Newline()

""
.newline()
.text(L10n.pangramArabic)
.font(.systemFont(ofSize: 40))
.baseWritingDirection(.rightToLeft)
.language(.arabic)

Newline()

""
.font(.systemFont(ofSize: 40))
.baseWritingDirection(.leftToRight)

Newline()

L10n.pangramHebrew
.baseWritingDirection(.rightToLeft)
}
}
]
}
}
Expand Down
2 changes: 1 addition & 1 deletion Example/Core/Sources/Core/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Ταχίστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός Takhístè alôpèx vaphês psèménè gè, draskelízei ypér nòthroý kynós"
"value" : "Ταχίστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός"
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 60;
objectVersion = 63;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -261,7 +261,7 @@
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1500;
LastUpgradeCheck = 1500;
LastUpgradeCheck = 1600;
TargetAttributes = {
893D9AEA2AF54E4600C1E69C = {
CreatedOnToolsVersion = 15.0.1;
Expand All @@ -278,7 +278,7 @@
};
};
buildConfigurationList = 893D9AE62AF54E4600C1E69C /* Build configuration list for PBXProject "Example" */;
compatibilityVersion = "Xcode 14.0";
compatibilityVersion = "Xcode 15.3";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
Expand Down Expand Up @@ -587,6 +587,7 @@
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_NSHumanReadableCopyright = "";
INFOPLIST_KEY_NSMainStoryboardFile = Main;
Expand All @@ -613,6 +614,7 @@
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_NSHumanReadableCopyright = "";
INFOPLIST_KEY_NSMainStoryboardFile = Main;
Expand Down Expand Up @@ -689,7 +691,6 @@
896CC0FE2B17AAF300FC2206 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
INFOPLIST_KEY_CFBundleDisplayName = ExampleWatchOS;
Expand All @@ -703,7 +704,6 @@
896CC0FF2B17AAF300FC2206 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
INFOPLIST_KEY_CFBundleDisplayName = ExampleWatchOS;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
LastUpgradeVersion = "1600"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
LastUpgradeVersion = "1600"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Loading

0 comments on commit bfcceb0

Please sign in to comment.