-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from bullinnyc/add-image-cache-property-wrapper
Add image cache property wrapper.
- Loading branch information
Showing
11 changed files
with
181 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
Sources/CachedAsyncImage/PropertyWrappers/ImageCache.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// ImageCache.swift | ||
// CachedAsyncImage | ||
// | ||
// Created by Dmitry Kononchuk on 07.01.2024. | ||
// Copyright © 2024 Dmitry Kononchuk. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
/// A property wrapper type that reflects a value from `TemporaryImageCache`. | ||
/// | ||
/// Read this value from within a view to access the image cache management. | ||
/// | ||
/// struct MyView: View { | ||
/// @ImageCache private var imageCache | ||
/// | ||
/// // ... | ||
/// } | ||
/// | ||
@propertyWrapper | ||
public struct ImageCache { | ||
// MARK: - Public Properties | ||
|
||
/// The wrapped value property provides primary access to the value’s data. | ||
public var wrappedValue: ImageCacheProtocol { | ||
get { storage.imageCache } | ||
nonmutating set { storage.imageCache = newValue } | ||
} | ||
|
||
// MARK: - Private Properties | ||
|
||
private let storage: FeatureStorage | ||
|
||
// MARK: - Initializers | ||
|
||
public init() { | ||
storage = FeatureStorage.shared | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// Network.swift | ||
// CachedAsyncImage | ||
// | ||
// Created by Dmitry Kononchuk on 07.01.2024. | ||
// Copyright © 2024 Dmitry Kononchuk. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
@propertyWrapper | ||
struct Network { | ||
// MARK: - Public Properties | ||
|
||
var wrappedValue: NetworkProtocol { | ||
get { storage.network } | ||
nonmutating set { storage.network = newValue } | ||
} | ||
|
||
// MARK: - Private Properties | ||
|
||
private let storage: FeatureStorage | ||
|
||
// MARK: - Initializers | ||
|
||
init() { | ||
storage = FeatureStorage.shared | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// FeatureStorage.swift | ||
// CachedAsyncImage | ||
// | ||
// Created by Dmitry Kononchuk on 07.01.2024. | ||
// Copyright © 2024 Dmitry Kononchuk. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
final class FeatureStorage { | ||
// MARK: - Public Properties | ||
|
||
var imageCache: ImageCacheProtocol = TemporaryImageCache() | ||
var network: NetworkProtocol = NetworkManager() | ||
|
||
static let shared = FeatureStorage() | ||
|
||
// MARK: - Private Initializers | ||
|
||
private init() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.