Skip to content

Commit

Permalink
Support visionOS
Browse files Browse the repository at this point in the history
  • Loading branch information
onmyway133 committed Jan 21, 2024
1 parent 99faa08 commit 53c895b
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 20 deletions.
7 changes: 7 additions & 0 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
// swift-tools-version:5.0
// swift-tools-version:5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "EasyStash",
platforms: [
.iOS(.v15),
.tvOS(.v13),
.macOS(.v12),
],
products: [
.library(
name: "EasyStash",
targets: ["EasyStash"]
),
],
dependencies: [
],
dependencies: [],
targets: [
.target(
name: "EasyStash",
Expand Down
4 changes: 2 additions & 2 deletions Sources/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public struct Options {

public init() {
#if os(tvOS)
searchPathDirectory = .cachesDirectory
searchPathDirectory = .cachesDirectory
#else
searchPathDirectory = .applicationSupportDirectory
searchPathDirectory = .applicationSupportDirectory
#endif
}
}
2 changes: 1 addition & 1 deletion Sources/Storage+Codable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public extension Storage {
}

func load<T: Codable>(forKey key: String, as: T.Type, withExpiry expiry: Expiry = .never) throws -> T {
func loadFromDisk<T: Codable>(forKey key: String, as: T.Type) throws -> T {
func loadFromDisk(forKey key: String, as: T.Type) throws -> T {
let data = try Data(contentsOf: fileUrl(forKey: key))
let decoder = options.decoder

Expand Down
4 changes: 2 additions & 2 deletions Sources/Storage+Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
//

#if canImport(UIKit)
import UIKit
import UIKit
#elseif canImport(AppKit)
import AppKit
import AppKit
#endif

public extension Storage {
Expand Down
21 changes: 11 additions & 10 deletions Sources/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
//

import Foundation

#if canImport(UIKit)
import UIKit
public typealias Image = UIImage
import UIKit
public typealias Image = UIImage
#elseif canImport(AppKit)
import AppKit
public typealias Image = NSImage
import AppKit
public typealias Image = NSImage
#endif

func unwrapOrThrow<T>(_ optional: Optional<T>, _ error: Error) throws -> T {
Expand Down Expand Up @@ -47,21 +48,21 @@ public struct TypeWrapper<T: Codable>: Codable {
class Utils {
static func image(data: Data) -> Image? {
#if canImport(UIKit)
return UIImage(data: data)
return UIImage(data: data)
#elseif canImport(AppKit)
return NSImage(data: data)
return NSImage(data: data)
#else
return nil
return nil
#endif
}

static func data(image: Image) -> Data? {
#if canImport(UIKit)
return image.jpegData(compressionQuality: 0.9)
return image.jpegData(compressionQuality: 0.9)
#elseif canImport(AppKit)
return image.tiffRepresentation
return image.tiffRepresentation
#else
return nil
return nil
#endif
}
}
Expand Down
3 changes: 2 additions & 1 deletion Tests/EasyStashTests/ImageGenerate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2019 Khoa Pham. All rights reserved.
//

#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)
import UIKit

extension UIColor {
Expand All @@ -21,6 +21,7 @@ extension UIColor {
}
}
}

#elseif os(OSX)
import AppKit

Expand Down
6 changes: 5 additions & 1 deletion Tests/EasyStashTests/iOSTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,11 @@ class iOSTests: XCTestCase {
func testPerformanceUsingKeyArchiver() {
let users = Array(0..<10_000).map { _ in User3(city: "Oslo", name: "A") }
measure {
NSKeyedArchiver.archivedData(withRootObject: users)
do {
try NSKeyedArchiver.archivedData(withRootObject: users, requiringSecureCoding: false)
} catch {

}
}
}
}
Expand Down

0 comments on commit 53c895b

Please sign in to comment.