Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
onmyway133 committed Nov 24, 2020
1 parent 37d8fae commit 2ca5427
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ github "onmyway133/EasyStash"
Add EasyStash as a dependency to your Package.swift. For more information, please see the [Swift Package Manager documentation](https://github.com/apple/swift-package-manager/tree/master/Documentation).

```swift
.package(url: "https://github.com/onmyway133/EasyStash", from: "1.1.1")
.package(url: "https://github.com/onmyway133/EasyStash", from: "1.1.7")
```

**EasyStash** can also be installed manually. Just download and drop `Sources` folders in your project.
Expand Down
16 changes: 13 additions & 3 deletions Sources/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,21 @@
import Foundation

public struct Options {
public var searchPathDirectory: FileManager.SearchPathDirectory = .applicationSupportDirectory
/// By default, files are saved into searchPathDirectory/folder
public var searchPathDirectory: FileManager.SearchPathDirectory
public var folder: String = (Bundle.main.bundleIdentifier ?? "").appending("/Default")

/// Optionally, you can set predefined directory for where to save files
public var directoryUrl: URL? = nil

public var encoder: JSONEncoder = JSONEncoder()
public var decoder: JSONDecoder = JSONDecoder()
public var directoryUrl: URL? = nil

public init() {}
public init() {
#if os(tvOS)
searchPathDirectory = .cachesDirectory
#else
searchPathDirectory = .applicationSupportDirectory
#endif
}
}
16 changes: 9 additions & 7 deletions Sources/Storage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public class Storage {
cache.removeObject(forKey: key as NSString)
try fileManager.removeItem(at: fileUrl(forKey: key))
}

public func fileUrl(forKey key: String) -> URL {
return folderUrl.appendingPathComponent(key, isDirectory: false)
}
}

extension Storage {
Expand All @@ -84,14 +88,12 @@ extension Storage {
try fileManager.setAttributes(attributes, ofItemAtPath: folderUrl.path)
#endif
}

func fileUrl(forKey key: String) -> URL {
return folderUrl.appendingPathComponent(key, isDirectory: false)
}

func verify(maxAge: TimeInterval,
forKey key: String,
fromDate date: @escaping (() -> Date) = { Date() }) throws -> Bool {
func verify(
maxAge: TimeInterval,
forKey key: String,
fromDate date: @escaping (() -> Date) = { Date() }
) throws -> Bool {
date().timeIntervalSince(try modificationDate(forKey: key)) <= maxAge
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/EasyStashTests/ImageGenerate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import UIKit

extension UIColor {
func image(_ size: CGSize = CGSize(width: 1, height: 1)) -> UIImage {
if #available(iOS 10.0, *) {
if #available(iOS 10.0, tvOS 10.0, *) {
return UIGraphicsImageRenderer(size: size).image { rendererContext in
self.setFill()
rendererContext.fill(CGRect(origin: .zero, size: size))
Expand Down

0 comments on commit 2ca5427

Please sign in to comment.