Skip to content

Commit

Permalink
platform support (#9)
Browse files Browse the repository at this point in the history
- fix build errors for swift 5.6
- support tvos and watchos
  • Loading branch information
juyan committed Jan 28, 2024
2 parents 9f2e14a + 429bdb5 commit 61aa52c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// swift-tools-version:5.5
// swift-tools-version:5.6
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "SwiftFileStore",
platforms: [.iOS(.v14), .macOS(.v12)],
platforms: [.iOS(.v14), .macOS(.v12), .tvOS(.v14), .watchOS(.v8)],
products: [
.library(
name: "SwiftFileStore",
Expand Down
9 changes: 9 additions & 0 deletions Sources/SwiftFileStore/PersistenceLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,21 @@ public actor PersistenceLogImpl<ElementType>: PersistenceLog where ElementType:
private let dirURL: URL
private let fileHandle: FileHandle

#if swift(>=5.7)
public init(name: String) throws {
let applicationSupportDir = try FileManager.default.url(for: .applicationSupportDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
let rootDir = applicationSupportDir.appendingPathComponent("persistence-log", isDirectory: true)
try FileManager.default.createDirIfNotExist(url: rootDir)
try self.init(name: name, rootDir: rootDir)
}
#else
public convenience init(name: String) throws {
let applicationSupportDir = try FileManager.default.url(for: .applicationSupportDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
let rootDir = applicationSupportDir.appendingPathComponent("persistence-log", isDirectory: true)
try FileManager.default.createDirIfNotExist(url: rootDir)
try self.init(name: name, rootDir: rootDir)
}
#endif

init(name: String, rootDir: URL) throws {
self.name = name
Expand Down
6 changes: 1 addition & 5 deletions Tests/SwiftFileStoreTests/PersistenceLogTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import XCTest

final class PersistenceLogTests: XCTestCase {
var log: (any TestObjectLog)!
var log: PersistenceLogImpl<TestObject>!

func test_append_flush() async throws {
log = try! PersistenceLogImpl<TestObject>(name: "test-queue")
Expand All @@ -18,7 +18,3 @@ final class PersistenceLogTests: XCTestCase {
XCTAssertEqual(result, [object1, object2])
}
}

protocol TestObjectLog: PersistenceLog where Element == TestObject {}

extension PersistenceLogImpl<TestObject>: TestObjectLog {}

0 comments on commit 61aa52c

Please sign in to comment.