Skip to content

Commit 6babc1e

Browse files
authored
Merge pull request #10 from bullinnyc/add-support-tvOS-watchOS-visionOS
Add support tvOS, watchOS, visionOS.
2 parents 43f008c + c8a115e commit 6babc1e

7 files changed

Lines changed: 46 additions & 16 deletions

File tree

.github/workflows/build-and-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
macos: ['macos-13']
1818
scheme: ['CachedAsyncImage']
1919
command: ['test']
20-
platform: ['macOS', 'iOS']
20+
platform: ['iOS', 'macOS', 'tvOS', 'watchOS']
2121
steps:
2222
- name: Switch xcode to ${{ matrix.xcode }}
2323
uses: maxim-lobanov/setup-xcode@v1.6.0

Examples/ContentView.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import SwiftUI
1010
import CachedAsyncImage
1111

12-
@available(iOS 15.0, macOS 12.0, *)
12+
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, visionOS 1.0, *)
1313
struct ContentView: View {
1414
// MARK: - Private Properties
1515

@@ -97,7 +97,7 @@ struct ContentView: View {
9797

9898
// MARK: - Ext. Configure views
9999

100-
@available(iOS 15.0, macOS 12.0, *)
100+
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, visionOS 1.0, *)
101101
extension ContentView {
102102
func placeholder(_ progress: String) -> some View {
103103
ZStack {
@@ -149,7 +149,7 @@ extension ContentView {
149149

150150
// MARK: - Preview Provider
151151

152-
@available(iOS 15.0, macOS 12.0, *)
152+
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, visionOS 1.0, *)
153153
struct ContentView_Previews: PreviewProvider {
154154
static var previews: some View {
155155
ContentView()

Package.swift

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

44
import PackageDescription
@@ -8,7 +8,10 @@ let package = Package(
88
platforms: [
99
// Add support for all platforms starting from a specific version.
1010
.iOS(.v14),
11-
.macOS(.v11)
11+
.macOS(.v11),
12+
.tvOS(.v14),
13+
.watchOS(.v7),
14+
.visionOS(.v1)
1215
],
1316
products: [
1417
// Products define the executables and libraries a package produces, making them visible to other packages.

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ struct MyView: View {
135135
```
136136

137137
## Requirements
138-
- iOS 14.0 +
139-
- macOS 11.0 +
138+
- iOS 14.0 + / macOS 11.0 + / tvOS 14.0 + / watchOS 7.0 + / visionOS 1.0 +
140139
- [SwiftUI](https://developer.apple.com/xcode/swiftui/)
141140

142141
## License

Sources/CachedAsyncImage/Resources/ResourcesManager.swift

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
#if canImport(UIKit)
1010
import UIKit
1111

12+
#if os(watchOS)
13+
import SwiftUI
14+
#endif
15+
1216
/// Resources manager typealias.
1317
public typealias RM = ResourcesManager
1418

@@ -17,11 +21,7 @@ public final class ResourcesManager {
1721
// MARK: - Public Properties
1822

1923
/// An object that stores color data.
20-
public static let snow = UIColor(
21-
named: "snow",
22-
in: Bundle.module,
23-
compatibleWith: nil
24-
) ?? UIColor()
24+
public static let snow = getColor(with: "snow")
2525

2626
// MARK: - Public Methods
2727

@@ -33,6 +33,20 @@ public final class ResourcesManager {
3333
public static func image(_ name: String) -> UIImage? {
3434
UIImage(named: name, in: Bundle.module, with: nil)
3535
}
36+
37+
// MARK: - Private Methods
38+
39+
private static func getColor(with name: String) -> UIColor {
40+
#if os(watchOS)
41+
UIColor(Color(name, bundle: Bundle.module))
42+
#elseif os(iOS) || os(tvOS) || os(visionOS)
43+
UIColor(
44+
named: name,
45+
in: Bundle.module,
46+
compatibleWith: nil
47+
) ?? UIColor()
48+
#endif
49+
}
3650
}
3751
#elseif canImport(AppKit)
3852
import AppKit

Sources/CachedAsyncImage/Services/CrossPlatformImage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Copyright © 2023 Dmitry Kononchuk. All rights reserved.
77
//
88

9-
#if os(iOS)
9+
#if os(iOS) || os(tvOS) || os(watchOS) || os(visionOS)
1010
import UIKit
1111
import SwiftUI
1212

Sources/CachedAsyncImage/Views/CachedAsyncImage.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,14 @@ struct CachedAsyncImage_Previews: PreviewProvider {
124124
.font(.footnote)
125125
.multilineTextAlignment(.center)
126126
.conditional { view in
127-
if #available(iOS 15.0, macOS 12.0, *) {
127+
if #available(
128+
iOS 15.0,
129+
macOS 12.0,
130+
tvOS 15.0,
131+
watchOS 8.0,
132+
visionOS 1.0,
133+
*
134+
) {
128135
view
129136
.foregroundStyle(.red)
130137
} else {
@@ -146,7 +153,14 @@ struct CachedAsyncImage_Previews: PreviewProvider {
146153
label: {
147154
Text("Retry")
148155
.conditional { view in
149-
if #available(iOS 15.0, macOS 12.0, *) {
156+
if #available(
157+
iOS 15.0,
158+
macOS 12.0,
159+
tvOS 15.0,
160+
watchOS 8.0,
161+
visionOS 1.0,
162+
*
163+
) {
150164
view
151165
.foregroundStyle(.black)
152166
} else {

0 commit comments

Comments
 (0)