Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ jobs:
action: test
warnings-as-errors: false
verbosity: xcbeautify

- name: Install SwiftLint
run: brew install swiftlint

- name: Run SwiftLint
run: swiftlint --config .swiftlint.yml --reporter github-actions-logging
31 changes: 31 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
included:
- AsyncImageView
- AsyncImageViewTests
- Package.swift

excluded:
- .build
- .swiftpm
- Example/Carthage
- Example/Pods
- Docs

opt_in_rules:
- empty_count
- explicit_init
- overridden_super_call
- redundant_nil_coalescing

analyzer_rules:
- unused_import
- unused_optional_binding

disabled_rules:
- force_cast
- function_body_length
- identifier_name
- line_length
- nesting
- private_over_fileprivate
- todo
- type_body_length
3 changes: 3 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Agent Instructions

- Always run `swiftlint --config .swiftlint.yml` from the repository root before submitting changes. This lints the AsyncImageView codebase with the shared configuration.
29 changes: 23 additions & 6 deletions AsyncImageView/Caching.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,14 @@ public protocol NSDataConvertible {
/// Returns the directory where all `DiskCache` caches are stored
/// by default.
public func diskCacheDefaultCacheDirectory() -> URL {
return try! FileManager()
.url(for: .cachesDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
.appendingPathComponent("AsyncImageView", isDirectory: true)
do {
return try FileManager()
.url(for: .cachesDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
.appendingPathComponent("AsyncImageView", isDirectory: true)
} catch {
assertionFailure("Failed to resolve caches directory: \(error)")
return FileManager.default.temporaryDirectory.appendingPathComponent("AsyncImageView", isDirectory: true)
}
}

/// `CacheType` backed by files on disk.
Expand Down Expand Up @@ -138,9 +143,17 @@ public final class DiskCache<K: DataFileType, V: NSDataConvertible>: CacheType {
self.guaranteeDirectoryExists(url.deletingLastPathComponent())

if let data = value.flatMap({ $0.data }) {
try! data.write(to: url, options: .atomicWrite)
do {
try data.write(to: url, options: .atomicWrite)
} catch {
assertionFailure("Failed to persist cache entry at \(url): \(error)")
}
} else if self.fileManager.fileExists(atPath: url.path) {
try! self.fileManager.removeItem(at: url)
do {
try self.fileManager.removeItem(at: url)
} catch {
assertionFailure("Failed to delete cache entry at \(url): \(error)")
}
}
}
}
Expand All @@ -165,6 +178,10 @@ public final class DiskCache<K: DataFileType, V: NSDataConvertible>: CacheType {
}

private func guaranteeDirectoryExists(_ url: URL) {
try! self.fileManager.createDirectory(at: url, withIntermediateDirectories: true, attributes: nil)
do {
try self.fileManager.createDirectory(at: url, withIntermediateDirectories: true, attributes: nil)
} catch {
assertionFailure("Failed to create cache directory at \(url): \(error)")
}
}
}
Loading