Skip to content

Commit 01a2b97

Browse files
authored
Merge pull request #6 from GoodRequest/feature/swift6
task: Swift 6 support
2 parents 3fae058 + b1e23f4 commit 01a2b97

File tree

18 files changed

+257
-138
lines changed

18 files changed

+257
-138
lines changed

.swiftpm/configuration/Package.resolved

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

GoodSwiftUI-Sample/GoodSwiftUI-Sample.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@
261261
SDKROOT = iphoneos;
262262
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
263263
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
264+
SWIFT_VERSION = 6.0;
264265
};
265266
name = Debug;
266267
};
@@ -314,6 +315,7 @@
314315
SDKROOT = iphoneos;
315316
SWIFT_COMPILATION_MODE = wholemodule;
316317
SWIFT_OPTIMIZATION_LEVEL = "-O";
318+
SWIFT_VERSION = 6.0;
317319
VALIDATE_PRODUCT = YES;
318320
};
319321
name = Release;

GoodSwiftUI-Sample/GoodSwiftUI-Sample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

GoodSwiftUI-Sample/GoodSwiftUI-Sample/Extensions/InputFieldViewConfiguration.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,28 @@ extension InputFieldView {
2424
eyeImageVisible: UIImage(systemName: "eye.slash"),
2525
enabled: InputFieldViewStateAppearance(
2626
placeholderColor: UIColor.darkGray,
27-
contentBackgroundColor: UIColor.white,
27+
contentBackgroundColor: UIColor.tertiarySystemBackground,
2828
textFieldTextColor: UIColor.systemBlue,
2929
borderColor: UIColor.gray,
3030
hintColor: UIColor.darkGray
3131
),
3232
selected: InputFieldViewStateAppearance(
3333
placeholderColor: UIColor.darkGray,
34-
contentBackgroundColor: UIColor.white,
34+
contentBackgroundColor: UIColor.tertiarySystemBackground,
3535
textFieldTextColor: UIColor.systemBlue,
3636
borderColor: UIColor.gray,
3737
hintColor: UIColor.darkGray
3838
),
3939
disabled: InputFieldViewStateAppearance(
4040
placeholderColor: UIColor.darkGray,
41-
contentBackgroundColor: UIColor.lightGray,
41+
contentBackgroundColor: UIColor.secondarySystemBackground,
4242
textFieldTextColor: UIColor.darkGray,
4343
borderColor: UIColor.gray,
4444
hintColor: UIColor.darkGray
4545
),
4646
failed: InputFieldViewStateAppearance(
4747
placeholderColor: UIColor.darkGray,
48-
contentBackgroundColor: UIColor.white,
48+
contentBackgroundColor: UIColor.tertiarySystemBackground,
4949
textFieldTextColor: UIColor.systemBlue,
5050
borderColor: UIColor.systemRed,
5151
hintColor: UIColor.systemRed

Package.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 5.9
1+
// swift-tools-version: 6.0
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
@@ -23,29 +23,33 @@ let package = Package(
2323
)
2424
],
2525
dependencies: [
26-
.package(url: "https://github.com/goodrequest/goodextensions-ios", .upToNextMinor(from: "1.6.0"))
26+
.package(url: "https://github.com/goodrequest/goodextensions-ios", .upToNextMajor(from: "2.0.0"))
2727
],
2828
targets: [
2929
.target(
3030
name: "GoodSwiftUI",
31-
dependencies: []
31+
dependencies: [],
32+
swiftSettings: [.swiftLanguageMode(.v6)]
3233
),
3334
.target(
3435
name: "GRAsyncImage",
3536
dependencies: [
3637
.product(name: "GoodExtensions", package: "GoodExtensions-iOS"),
37-
]
38+
],
39+
swiftSettings: [.swiftLanguageMode(.v6)]
3840
),
3941
.target(
4042
name: "GRInputField",
4143
dependencies: [
4244
.product(name: "GoodExtensions", package: "GoodExtensions-iOS"),
4345
.product(name: "GoodStructs", package: "GoodExtensions-iOS")
44-
]
46+
],
47+
swiftSettings: [.swiftLanguageMode(.v6), .unsafeFlags(["-Onone"])]
4548
),
4649
.testTarget(
4750
name: "GoodSwiftUITests",
48-
dependencies: ["GoodSwiftUI"]
51+
dependencies: ["GoodSwiftUI"],
52+
swiftSettings: [.swiftLanguageMode(.v6)]
4953
),
5054
]
5155
)

Sources/GRAsyncImage/GRAsyncImage.swift

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public struct GRAsyncImage<FailurePlaceholder: View, LoadingPlaceholder: View>:
3434
onSuccess: VoidClosure? = nil,
3535
onFailure: VoidClosure? = nil
3636
) {
37-
_imageLoader = StateObject(wrappedValue: GRImageLoader(url: url, imageCache: DefaultImageCache.shared))
37+
_imageLoader = StateObject(wrappedValue: GRImageLoader(url: url))
3838

3939
self.url = url
4040
self.failurePlaceholder = failurePlaceholder()
@@ -58,12 +58,12 @@ public struct GRAsyncImage<FailurePlaceholder: View, LoadingPlaceholder: View>:
5858
Image(uiImage: image)
5959
.resizable()
6060
} else {
61-
Button(action: { loadImage(url: url) }, label: { failurePlaceholder })
61+
Button(action: { startLoadingImage(url: url) }, label: { failurePlaceholder })
6262
}
6363

6464
case .failure:
65-
if let url, allowsReloading {
66-
Button(action: { loadImage(url: url) }, label: { failurePlaceholder })
65+
if allowsReloading {
66+
Button(action: { startLoadingImage(url: url) }, label: { failurePlaceholder })
6767
} else {
6868
failurePlaceholder
6969
}
@@ -72,8 +72,8 @@ public struct GRAsyncImage<FailurePlaceholder: View, LoadingPlaceholder: View>:
7272
Color.clear
7373
}
7474
}
75-
.onAppear { loadImage(url: url) }
76-
.onChange(of: url) { url in loadImage(url: url) }
75+
.onAppear { startLoadingImage(url: url) }
76+
.onChange(of: url) { url in startLoadingImage(url: url) }
7777
.onChange(of: imageLoader.status) {
7878
switch $0 {
7979
case .loading:
@@ -93,23 +93,14 @@ public struct GRAsyncImage<FailurePlaceholder: View, LoadingPlaceholder: View>:
9393

9494
// MARK: - Private
9595

96-
private func loadImage(url: URL?) {
96+
private func startLoadingImage(url: URL?) {
9797
Task {
9898
await imageLoader.load(url)
9999
}
100100
}
101101

102102
}
103103

104-
@available(iOS 14.0, *)
105-
extension GRAsyncImage: Equatable {
106-
107-
public static func == (lhs: GRAsyncImage, rhs: GRAsyncImage) -> Bool {
108-
lhs.url == rhs.url
109-
}
110-
111-
}
112-
113104
@available(iOS 14.0, *)
114105
struct GRAsyncImage_Previews: PreviewProvider {
115106

Sources/GRAsyncImage/GRImageCache.swift

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,14 @@
77

88
import Foundation
99

10-
public protocol GRImageCacheType {
11-
12-
func object(forKey url: NSURL) -> Data?
13-
func set(object: NSData, forKey url: NSURL)
14-
15-
}
16-
17-
final class DefaultImageCache {
10+
@MainActor final class GRImageCache {
1811

1912
// MARK: - Typealiases
2013

2114
typealias ImageCache = NSCache<NSURL, NSData>
2215

2316
// MARK: - Properties
2417

25-
static var shared = DefaultImageCache()
26-
2718
private lazy var cache: ImageCache = {
2819
let cache = ImageCache()
2920
cache.countLimit = 100
@@ -32,23 +23,20 @@ final class DefaultImageCache {
3223
return cache
3324
}()
3425

35-
// MARK: - Initialization
26+
// MARK: - Singleton
3627

37-
private init() {}
38-
39-
}
28+
static let shared = GRImageCache()
4029

41-
// MARK: - Protocol implementation
30+
private init() {}
4231

43-
extension DefaultImageCache: GRImageCacheType {
32+
// MARK: - Internal
4433

4534
func object(forKey url: NSURL) -> Data? {
4635
return cache.object(forKey: url) as? Data
4736
}
4837

49-
func set(object: NSData, forKey url: NSURL) {
50-
cache.setObject(object, forKey: url)
38+
func set(object: Data, forKey url: URL) {
39+
cache.setObject(object as NSData, forKey: url as NSURL)
5140
}
5241

5342
}
54-

Sources/GRAsyncImage/GRImageLoader.swift

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@
77

88
import SwiftUI
99

10-
final class GRImageLoader: ObservableObject {
10+
@MainActor final class GRImageLoader: ObservableObject {
1111

1212
// MARK: - Properties
1313

1414
@Published private(set) var status: Status
1515

16-
private var imageCache: GRImageCacheType
17-
1816
// MARK: - Enums
1917

2018
enum Status: Equatable {
@@ -28,10 +26,8 @@ final class GRImageLoader: ObservableObject {
2826

2927
// MARK: - Initialization
3028

31-
init(url: URL?, imageCache: GRImageCacheType) {
32-
self.imageCache = imageCache
33-
34-
if let url = url, let data = imageCache.object(forKey: url as NSURL) {
29+
init(url: URL?) {
30+
if let url = url, let data = GRImageCache.shared.object(forKey: url as NSURL) {
3531
status = .success(data)
3632
} else {
3733
status = .idle
@@ -40,14 +36,13 @@ final class GRImageLoader: ObservableObject {
4036

4137
// MARK: - Public
4238

43-
@MainActor
4439
func load(_ url: URL?) async {
4540
guard let url = url else {
4641
status = .failure
4742
return
4843
}
4944

50-
if let data = imageCache.object(forKey: url as NSURL) {
45+
if let data = GRImageCache.shared.object(forKey: url as NSURL) {
5146
status = .success(data)
5247
return
5348
}
@@ -57,7 +52,7 @@ final class GRImageLoader: ObservableObject {
5752
do {
5853
let (data, _) = try await URLSession.shared.data(from: url)
5954
status = .success(data)
60-
imageCache.set(object: data as NSData, forKey: url as NSURL)
55+
GRImageCache.shared.set(object: data, forKey: url)
6156
} catch {
6257
status = .failure
6358
}

Sources/GRInputField/Common/InputFieldAppearance.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77

88
import UIKit
99

10-
public struct InputFieldAppearance {
10+
public struct InputFieldAppearance: Sendable {
1111

1212
public var titleFont: UIFont?
1313
public var titleColor: UIColor?
1414

15+
/// Tint color of text field - eg. typing indicator
1516
public var textFieldTintColor: UIColor?
1617
public var textFieldFont: UIFont?
1718

@@ -65,7 +66,7 @@ public struct InputFieldAppearance {
6566

6667
}
6768

68-
public struct InputFieldViewStateAppearance {
69+
public struct InputFieldViewStateAppearance: Sendable {
6970

7071
public var placeholderColor: UIColor?
7172
public var contentBackgroundColor: UIColor?

Sources/GRInputField/Common/InputFieldTraits.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import UIKit
99

10-
public struct InputFieldTraits {
10+
public struct InputFieldTraits: Sendable {
1111

1212
public var textContentType: UITextContentType?
1313
public var autocapitalizationType: UITextAutocapitalizationType = .none

0 commit comments

Comments
 (0)