Skip to content

Commit 3b0016e

Browse files
jlawtonarjankowski
andauthored
fix: Make code compatible with macOS. (#900)
* fix: Remove unconditional iOS requirements. * Fix linter error --------- Co-authored-by: Artur Jankowski <[email protected]>
1 parent af5f0e5 commit 3b0016e

File tree

5 files changed

+22
-16
lines changed

5 files changed

+22
-16
lines changed

Sources/Core/BoxJSONDecoder.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//
88

99
import Foundation
10-
import UIKit
1110

1211
// swiftlint:disable:next convenience_type
1312
class BoxJSONDecoder {
@@ -152,12 +151,12 @@ class BoxJSONDecoder {
152151
return url
153152
}
154153

155-
static func optionalDecodeColor(json: [String: Any], forKey key: String) throws -> UIColor? {
154+
static func optionalDecodeColor(json: [String: Any], forKey key: String) throws -> PlatformColor? {
156155
guard let value: String = try optionalExtractJSON(json: json, key: key), !value.isEmpty else {
157156
return nil
158157
}
159158

160-
guard let color = UIColor(hex: value) else {
159+
guard let color = PlatformColor(hex: value) else {
161160
throw BoxCodingError(message: .invalidValueFormat(key: key))
162161
}
163162

Sources/Core/Extensions/UIColorExtension.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,19 @@
66
// Copyright © 2020 box. All rights reserved.
77
//
88

9-
import UIKit
9+
#if canImport(UIKit)
10+
import UIKit
1011

11-
extension UIColor {
12+
/// The color type used natively on the target platform.
13+
public typealias PlatformColor = UIColor
14+
#elseif canImport(AppKit)
15+
import AppKit
16+
17+
/// The color type used natively on the target platform.
18+
public typealias PlatformColor = NSColor
19+
#endif
20+
21+
extension PlatformColor {
1222
convenience init?(hex: String) {
1323
let red, green, blue, alpha: CGFloat
1424
if hex.hasPrefix("#") {

Sources/Core/MimeTypeProvider.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77
//
88

99
import Foundation
10-
#if os(iOS)
11-
#if canImport(UniformTypeIdentifiers)
12-
import UniformTypeIdentifiers
13-
#endif
14-
15-
#if canImport(MobileCoreServices)
16-
import MobileCoreServices
17-
#endif
10+
11+
#if canImport(UniformTypeIdentifiers)
12+
import UniformTypeIdentifiers
13+
#endif
14+
15+
#if canImport(MobileCoreServices)
16+
import MobileCoreServices
1817
#endif
1918

2019
/// Provides method for converting given filename to mime type

Sources/Modules/FoldersModule+Async.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//
88

99
import Foundation
10-
import UIKit
1110

1211
@available(iOS 13.0, *)
1312
public extension FoldersModule {

Sources/Responses/Classification.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77
//
88

99
import Foundation
10-
import UIKit
1110

1211
/// Details about the classification applied to a Box file or folder
1312
public class Classification: BoxModel {
1413
// MARK: - Properties
1514

1615
public private(set) var rawData: [String: Any]
1716
/// The color that is used to display the classification label in a user-interface
18-
public let color: UIColor?
17+
public let color: PlatformColor?
1918
/// An explanation of the meaning of this classification
2019
public let definition: String?
2120
/// Name of the classification

0 commit comments

Comments
 (0)