Skip to content

Commit fa40c35

Browse files
authored
Merge branch 'master' into support-watchos
2 parents 3116f50 + ec9f3af commit fa40c35

23 files changed

+271
-100
lines changed

Cache.podspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22
s.name = "Cache"
33
s.summary = "Nothing but cache."
4-
s.version = "6.0.0"
4+
s.version = "7.0.1"
55
s.homepage = "https://github.com/hyperoslo/Cache"
66
s.license = 'MIT'
77
s.author = { "Hyper Interaktiv AS" => "[email protected]" }
@@ -18,6 +18,7 @@ Pod::Spec.new do |s|
1818
s.osx.source_files = 'Source/{Mac,Shared}/**/*'
1919
s.tvos.source_files = 'Source/{iOS,Shared}/**/*'
2020
s.watchos.source_files = 'Source/{iOS,Shared}/**/*'
21+
s.resources = 'Source/PrivacyInfo.xcprivacy'
2122

2223
s.frameworks = 'Foundation'
2324
s.swift_version = '5.0'

Cache.xcodeproj/project.pbxproj

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
0E79164B250E2AA500A71666 /* Hasher+constantAccrossExecutions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E791649250E2AA500A71666 /* Hasher+constantAccrossExecutions.swift */; };
1212
0E79164C250E2AA500A71666 /* Hasher+constantAccrossExecutions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E791649250E2AA500A71666 /* Hasher+constantAccrossExecutions.swift */; };
1313
0E79164E250E2B0400A71666 /* Hasher+constantAccrossExecutions+Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E79164D250E2B0400A71666 /* Hasher+constantAccrossExecutions+Tests.swift */; };
14+
2292AB7B252A14520031F3B9 /* URL+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2292AB7A252A14520031F3B9 /* URL+Extensions.swift */; };
15+
2292AB7C252A14520031F3B9 /* URL+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2292AB7A252A14520031F3B9 /* URL+Extensions.swift */; };
16+
2292AB7D252A14520031F3B9 /* URL+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2292AB7A252A14520031F3B9 /* URL+Extensions.swift */; };
17+
2292AB85252A14F50031F3B9 /* FileManager+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2292AB84252A14F50031F3B9 /* FileManager+Extensions.swift */; };
18+
2292AB86252A14F50031F3B9 /* FileManager+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2292AB84252A14F50031F3B9 /* FileManager+Extensions.swift */; };
19+
2292AB87252A14F50031F3B9 /* FileManager+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2292AB84252A14F50031F3B9 /* FileManager+Extensions.swift */; };
1420
BDEDD37D1DBCEB8A007416A6 /* Cache.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BDEDD3561DBCE5B1007416A6 /* Cache.framework */; };
1521
D21B667C1F6A723C00125DE1 /* DataSerializer.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2CF98531F694FFA00CE8F68 /* DataSerializer.swift */; };
1622
D21B667E1F6A723C00125DE1 /* ExpirationMode.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2CF98551F694FFA00CE8F68 /* ExpirationMode.swift */; };
@@ -95,9 +101,6 @@
95101
D28A1D241F6FFEF60030DF81 /* ObjectConverterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D285143E1F6FFE1F00C674D1 /* ObjectConverterTests.swift */; };
96102
D28C9BAC1F67ECD400C180C1 /* TestHelper+iOS.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5291CDF1C28374800B702C9 /* TestHelper+iOS.swift */; };
97103
D28C9BAF1F67EF8300C180C1 /* UIImage+ExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5291DA01C28405900B702C9 /* UIImage+ExtensionsTests.swift */; };
98-
D292DAFD1F6A970B0060F614 /* Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = D292DAFC1F6A970B0060F614 /* Result.swift */; };
99-
D292DAFE1F6A970B0060F614 /* Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = D292DAFC1F6A970B0060F614 /* Result.swift */; };
100-
D292DAFF1F6A970B0060F614 /* Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = D292DAFC1F6A970B0060F614 /* Result.swift */; };
101104
D2CF981E1F69427C00CE8F68 /* TestCase+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2CF981B1F69427C00CE8F68 /* TestCase+Extensions.swift */; };
102105
D2CF981F1F69427C00CE8F68 /* TestCase+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2CF981B1F69427C00CE8F68 /* TestCase+Extensions.swift */; };
103106
D2CF98201F69427C00CE8F68 /* TestCase+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2CF981B1F69427C00CE8F68 /* TestCase+Extensions.swift */; };
@@ -213,6 +216,8 @@
213216
/* Begin PBXFileReference section */
214217
0E791649250E2AA500A71666 /* Hasher+constantAccrossExecutions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Hasher+constantAccrossExecutions.swift"; sourceTree = "<group>"; };
215218
0E79164D250E2B0400A71666 /* Hasher+constantAccrossExecutions+Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Hasher+constantAccrossExecutions+Tests.swift"; sourceTree = "<group>"; };
219+
2292AB7A252A14520031F3B9 /* URL+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "URL+Extensions.swift"; sourceTree = "<group>"; };
220+
2292AB84252A14F50031F3B9 /* FileManager+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FileManager+Extensions.swift"; sourceTree = "<group>"; };
216221
BDEDD3561DBCE5B1007416A6 /* Cache.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Cache.framework; sourceTree = BUILT_PRODUCTS_DIR; };
217222
BDEDD3781DBCEB8A007416A6 /* Cache-tvOS-Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Cache-tvOS-Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
218223
D221E5BB20D00D9300BC940E /* MemoryStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MemoryStorage.swift; sourceTree = "<group>"; };
@@ -232,7 +237,6 @@
232237
D27014A420D129EB003B45C7 /* TransformerFactory.swift */ = {isa = PBXFileReference; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = TransformerFactory.swift; sourceTree = "<group>"; tabWidth = 4; };
233238
D285143E1F6FFE1F00C674D1 /* ObjectConverterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObjectConverterTests.swift; sourceTree = "<group>"; };
234239
D28897041F8B79B300C61DEE /* JSONDecoder+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "JSONDecoder+Extensions.swift"; sourceTree = "<group>"; };
235-
D292DAFC1F6A970B0060F614 /* Result.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Result.swift; sourceTree = "<group>"; };
236240
D292DB001F6AA06B0060F614 /* SyncStorageTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SyncStorageTests.swift; sourceTree = "<group>"; };
237241
D292DB031F6AA0730060F614 /* AsyncStorageTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AsyncStorageTests.swift; sourceTree = "<group>"; };
238242
D2CF981B1F69427C00CE8F68 /* TestCase+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "TestCase+Extensions.swift"; sourceTree = "<group>"; };
@@ -376,6 +380,8 @@
376380
0E791649250E2AA500A71666 /* Hasher+constantAccrossExecutions.swift */,
377381
D28897041F8B79B300C61DEE /* JSONDecoder+Extensions.swift */,
378382
D2CF98501F694FFA00CE8F68 /* Date+Extensions.swift */,
383+
2292AB7A252A14520031F3B9 /* URL+Extensions.swift */,
384+
2292AB84252A14F50031F3B9 /* FileManager+Extensions.swift */,
379385
);
380386
path = Extensions;
381387
sourceTree = "<group>";
@@ -389,7 +395,6 @@
389395
D2CF98571F694FFA00CE8F68 /* ImageWrapper.swift */,
390396
D2CF98591F694FFA00CE8F68 /* StorageError.swift */,
391397
D2CF98861F695B8F00CE8F68 /* Types.swift */,
392-
D292DAFC1F6A970B0060F614 /* Result.swift */,
393398
D2D4CC151FA3145000E4A2D5 /* MD5.swift */,
394399
D2D4CC1F1FA3411300E4A2D5 /* JSONDictionaryWrapper.swift */,
395400
D2D4CC231FA3426B00E4A2D5 /* JSONArrayWrapper.swift */,
@@ -884,10 +889,11 @@
884889
D2D4CC261FA3426B00E4A2D5 /* JSONArrayWrapper.swift in Sources */,
885890
D27014A720D129EB003B45C7 /* TransformerFactory.swift in Sources */,
886891
D270147E20D107DA003B45C7 /* SyncStorage.swift in Sources */,
887-
D292DAFF1F6A970B0060F614 /* Result.swift in Sources */,
892+
2292AB7D252A14520031F3B9 /* URL+Extensions.swift in Sources */,
888893
D21B669A1F6A724300125DE1 /* Date+Extensions.swift in Sources */,
889894
0E79164C250E2AA500A71666 /* Hasher+constantAccrossExecutions.swift in Sources */,
890895
D21B66891F6A723C00125DE1 /* ImageWrapper.swift in Sources */,
896+
2292AB87252A14F50031F3B9 /* FileManager+Extensions.swift in Sources */,
891897
D21B668B1F6A723C00125DE1 /* StorageError.swift in Sources */,
892898
D5A9D1B921134547005DBD3F /* ObservationToken.swift in Sources */,
893899
D270148A20D11040003B45C7 /* Storage+Transform.swift in Sources */,
@@ -972,10 +978,11 @@
972978
D2D4CC251FA3426B00E4A2D5 /* JSONArrayWrapper.swift in Sources */,
973979
D27014A620D129EB003B45C7 /* TransformerFactory.swift in Sources */,
974980
D270147D20D107DA003B45C7 /* SyncStorage.swift in Sources */,
975-
D292DAFE1F6A970B0060F614 /* Result.swift in Sources */,
981+
2292AB7C252A14520031F3B9 /* URL+Extensions.swift in Sources */,
976982
D21B66991F6A724200125DE1 /* Date+Extensions.swift in Sources */,
977983
0E79164B250E2AA500A71666 /* Hasher+constantAccrossExecutions.swift in Sources */,
978984
D21B66801F6A723C00125DE1 /* ImageWrapper.swift in Sources */,
985+
2292AB86252A14F50031F3B9 /* FileManager+Extensions.swift in Sources */,
979986
D21B66821F6A723C00125DE1 /* StorageError.swift in Sources */,
980987
D5A9D1B821134547005DBD3F /* ObservationToken.swift in Sources */,
981988
D270148920D11040003B45C7 /* Storage+Transform.swift in Sources */,
@@ -1023,13 +1030,14 @@
10231030
D270148C20D113EA003B45C7 /* Optional+Extension.swift in Sources */,
10241031
D2CF98601F694FFA00CE8F68 /* DiskConfig.swift in Sources */,
10251032
D270147020D1018A003B45C7 /* Transformer.swift in Sources */,
1026-
D292DAFD1F6A970B0060F614 /* Result.swift in Sources */,
10271033
D27014A520D129EB003B45C7 /* TransformerFactory.swift in Sources */,
10281034
D2D4CC241FA3426B00E4A2D5 /* JSONArrayWrapper.swift in Sources */,
1035+
2292AB7B252A14520031F3B9 /* URL+Extensions.swift in Sources */,
10291036
D270147C20D107DA003B45C7 /* SyncStorage.swift in Sources */,
10301037
D2CF98671F694FFA00CE8F68 /* Expiry.swift in Sources */,
10311038
0E79164A250E2AA500A71666 /* Hasher+constantAccrossExecutions.swift in Sources */,
10321039
D270148820D11040003B45C7 /* Storage+Transform.swift in Sources */,
1040+
2292AB85252A14F50031F3B9 /* FileManager+Extensions.swift in Sources */,
10331041
D2CF986A1F694FFA00CE8F68 /* StorageError.swift in Sources */,
10341042
D5A9D1B721134547005DBD3F /* ObservationToken.swift in Sources */,
10351043
D5A138C11EB29BFA00881A20 /* UIImage+Extensions.swift in Sources */,
@@ -1174,6 +1182,7 @@
11741182
SDKROOT = appletvos;
11751183
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
11761184
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
1185+
TARGETED_DEVICE_FAMILY = 3;
11771186
TVOS_DEPLOYMENT_TARGET = 12.0;
11781187
};
11791188
name = Debug;
@@ -1192,6 +1201,7 @@
11921201
PRODUCT_BUNDLE_IDENTIFIER = "no.hyper.Cache-tvOS-Tests";
11931202
PRODUCT_NAME = "$(TARGET_NAME)";
11941203
SDKROOT = appletvos;
1204+
TARGETED_DEVICE_FAMILY = 3;
11951205
TVOS_DEPLOYMENT_TARGET = 12.0;
11961206
};
11971207
name = Release;
@@ -1273,7 +1283,7 @@
12731283
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
12741284
INFOPLIST_FILE = "$(SRCROOT)/Tests/Mac/Info.plist";
12751285
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
1276-
MACOSX_DEPLOYMENT_TARGET = 10.13;
1286+
MACOSX_DEPLOYMENT_TARGET = 10.15;
12771287
PRODUCT_BUNDLE_IDENTIFIER = "no.hyper.Cache-MacTests";
12781288
PRODUCT_NAME = "$(TARGET_NAME)";
12791289
SDKROOT = macosx;
@@ -1288,7 +1298,7 @@
12881298
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
12891299
INFOPLIST_FILE = "$(SRCROOT)/Tests/Mac/Info.plist";
12901300
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
1291-
MACOSX_DEPLOYMENT_TARGET = 10.13;
1301+
MACOSX_DEPLOYMENT_TARGET = 10.15;
12921302
PRODUCT_BUNDLE_IDENTIFIER = "no.hyper.Cache-MacTests";
12931303
PRODUCT_NAME = "$(TARGET_NAME)";
12941304
SDKROOT = macosx;

Cache.xcodeproj/xcshareddata/xcschemes/Cache-iOS.xcscheme

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
<Testables>
4040
<TestableReference
4141
skipped = "NO"
42-
parallelizable = "YES"
4342
testExecutionOrdering = "random">
4443
<BuildableReference
4544
BuildableIdentifier = "primary"

Package.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.1
1+
// swift-tools-version:5.5
22

33
import PackageDescription
44

@@ -14,7 +14,8 @@ let package = Package(
1414
.target(
1515
name: "Cache",
1616
path: "Source",
17-
exclude: ["Library/ImageWrapper.swift"]),
17+
resources: [.copy("PrivacyInfo.xcprivacy")]
18+
),
1819
.testTarget(
1920
name: "CacheTests",
2021
dependencies: ["Cache"],

README.md

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[![License](https://img.shields.io/cocoapods/l/Cache.svg?style=flat)](http://cocoadocs.org/docsets/Cache)
77
[![Platform](https://img.shields.io/cocoapods/p/Cache.svg?style=flat)](http://cocoadocs.org/docsets/Cache)
88
[![Documentation](https://img.shields.io/cocoapods/metrics/doc-percent/Cache.svg?style=flat)](http://cocoadocs.org/docsets/Cache)
9-
![Swift](https://img.shields.io/badge/%20in-swift%204.0-orange.svg)
9+
![Swift](https://img.shields.io/badge/%20in-swift%205-orange.svg)
1010

1111
## Table of Contents
1212

@@ -75,7 +75,7 @@ let memoryConfig = MemoryConfig(expiry: .never, countLimit: 10, totalCostLimit:
7575
let storage = try? Storage(
7676
diskConfig: diskConfig,
7777
memoryConfig: memoryConfig,
78-
transformer: TransformerFactory.forCodable(ofType: User.self) // Storage<User>
78+
transformer: TransformerFactory.forCodable(ofType: User.self) // Storage<String, User>
7979
)
8080
```
8181

@@ -86,13 +86,13 @@ All `Storage` now are generic by default, so you can get a type safety experienc
8686
If you want to change the type, `Cache` offers `transform` functions, look for `Transformer` and `TransformerFactory` for built-in transformers.
8787

8888
```swift
89-
let storage: Storage<User> = ...
89+
let storage: Storage<String, User> = ...
9090
storage.setObject(superman, forKey: "user")
9191

92-
let imageStorage = storage.transformImage() // Storage<UIImage>
92+
let imageStorage = storage.transformImage() // Storage<String, UIImage>
9393
imageStorage.setObject(image, forKey: "image")
9494

95-
let stringStorage = storage.transformCodable(ofType: String.self) // Storage<String>
95+
let stringStorage = storage.transformCodable(ofType: String.self) // Storage<String, String>
9696
stringStorage.setObject("hello world", forKey: "string")
9797
```
9898

@@ -247,42 +247,42 @@ You access Async APIs via `storage.async`, it is also thread safe, and you can u
247247
```swift
248248
storage.async.setObject("Oslo", forKey: "my favorite city") { result in
249249
switch result {
250-
case .value:
250+
case .success:
251251
print("saved successfully")
252-
case .error(let error):
252+
case .failure(let error):
253253
print(error)
254254
}
255255
}
256256

257257
storage.async.object(forKey: "my favorite city") { result in
258258
switch result {
259-
case .value(let city):
259+
case .success(let city):
260260
print("my favorite city is \(city)")
261-
case .error(let error):
261+
case .failure(let error):
262262
print(error)
263263
}
264264
}
265265

266266
storage.async.existsObject(forKey: "my favorite city") { result in
267-
if case .value(let exists) = result, exists {
267+
if case .success(let exists) = result, exists {
268268
print("I have a favorite city")
269269
}
270270
}
271271

272272
storage.async.removeAll() { result in
273273
switch result {
274-
case .value:
274+
case .success:
275275
print("removal completes")
276-
case .error(let error):
276+
case .failure(let error):
277277
print(error)
278278
}
279279
}
280280

281281
storage.async.removeExpiredObjects() { result in
282282
switch result {
283-
case .value:
283+
case .success:
284284
print("removal completes")
285-
case .error(let error):
285+
case .failure(let error):
286286
print(error)
287287
}
288288
}
@@ -381,7 +381,7 @@ This is how you perform object converting and saving with `Alamofire`
381381
```swift
382382
Alamofire.request("https://gameofthrones.org/mostFavoriteCharacter").responseString { response in
383383
do {
384-
let user = try JSONDecoder.decode(response.result.value, to: User.self)
384+
let user = try JSONDecoder.decode(response.result.success, to: User.self)
385385
try storage.setObject(user, forKey: "most favorite character")
386386
} catch {
387387
print(error)
@@ -391,17 +391,18 @@ Alamofire.request("https://gameofthrones.org/mostFavoriteCharacter").responseStr
391391

392392
## What about images
393393

394-
If you want to load image into `UIImageView` or `NSImageView`, then we also have a nice gift for you. It's called [Imaginary](https://github.com/hyperoslo/Imaginary) and uses `Cache` under the hood to make you life easier when it comes to working with remote images.
394+
If you want to load image into `UIImageView` or `NSImageView`, then we also have a nice gift for you. It's called [Imaginary](https://github.com/hyperoslo/Imaginary) and uses `Cache` under the hood to make your life easier when it comes to working with remote images.
395395

396396
## Installation
397397

398398
### Cocoapods
399399

400400
**Cache** is available through [CocoaPods](http://cocoapods.org). To install
401-
it, simply add the following line to your Podfile:
401+
it or update it, use the following line to your Podfile:
402402

403403
```ruby
404-
pod 'Cache'
404+
pod 'Cache', :git => 'https://github.com/hyperoslo/Cache.git'
405+
405406
```
406407

407408
### Carthage

Source/Mac/NSImage+Extensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if canImport(AppKit)
1+
#if canImport(AppKit) && !targetEnvironment(macCatalyst)
22
import AppKit
33

44
/// Helper UIImage extension.

Source/PrivacyInfo.xcprivacy

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>NSPrivacyCollectedDataTypes</key>
6+
<array/>
7+
<key>NSPrivacyAccessedAPITypes</key>
8+
<array>
9+
<dict>
10+
<key>NSPrivacyAccessedAPITypeReasons</key>
11+
<array>
12+
<string>C617.1</string>
13+
</array>
14+
<key>NSPrivacyAccessedAPIType</key>
15+
<string>NSPrivacyAccessedAPICategoryFileTimestamp</string>
16+
</dict>
17+
</array>
18+
</dict>
19+
</plist>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
import Foundation
3+
4+
extension FileManager {
5+
/**
6+
Calculates the size of the directory at the provided `URL`
7+
- parameter url: the directory url
8+
- returns: the size of the provided directory in bytes
9+
*/
10+
public func sizeOfDirectory(at url: URL) -> Int? {
11+
guard let enumerator = self.enumerator(at: url, includingPropertiesForKeys: [], options: [], errorHandler: { _, _ -> Bool in
12+
return false
13+
}) else {
14+
return nil
15+
}
16+
var size = 0
17+
for case let url as URL in enumerator {
18+
size += url.fileSize ?? 0
19+
}
20+
return size
21+
}
22+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
import Foundation
3+
4+
extension URL {
5+
/// Returns the file size of the file at the given `URL` in bytes
6+
var fileSize: Int? {
7+
do {
8+
let file = try self.resourceValues(forKeys: [.totalFileAllocatedSizeKey, .fileAllocatedSizeKey])
9+
return file.totalFileAllocatedSize ?? file.fileAllocatedSize
10+
} catch {
11+
return nil
12+
}
13+
}
14+
}

Source/Shared/Library/Result.swift

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)