Skip to content

Commit b6241aa

Browse files
committed
[#698] Resolve comment
1 parent c9a3fbe commit b6241aa

6 files changed

Lines changed: 20 additions & 29 deletions

File tree

template/Modules/Data/Sources/Repositories/RatingPromptStorage.swift

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import Domain
22
import Foundation
33

4-
final class RatingPromptStorage: RatingPromptStorageProtocol, @unchecked Sendable {
4+
actor RatingPromptStorage: RatingPromptStorageProtocol {
55

66
private let userDefaultsManager: UserDefaultsManagerProtocol
7-
private let lock = NSLock()
87

98
init(userDefaultsManager: UserDefaultsManagerProtocol) {
109
self.userDefaultsManager = userDefaultsManager
1110
}
1211

13-
func getRatingPromptData() -> RatingPromptData {
12+
func getRatingPromptData() async -> RatingPromptData {
1413
let appLaunchCount = userDefaultsManager.getIntValue(for: UserDefaultsKey.ratingPromptAppLaunchCount.rawValue)
1514
let firstLaunchDateData = userDefaultsManager.getDataValue(for: UserDefaultsKey.ratingPromptFirstLaunchDate.rawValue)
1615
let lastPromptedVersion = userDefaultsManager.getStringValue(for: UserDefaultsKey.ratingPromptLastPromptedVersion.rawValue)
@@ -29,10 +28,7 @@ final class RatingPromptStorage: RatingPromptStorageProtocol, @unchecked Sendabl
2928
)
3029
}
3130

32-
func recordAppLaunch() {
33-
lock.lock()
34-
defer { lock.unlock() }
35-
31+
func recordAppLaunch() async {
3632
let currentCount = userDefaultsManager.getIntValue(for: UserDefaultsKey.ratingPromptAppLaunchCount.rawValue)
3733
userDefaultsManager.set(currentCount + 1, for: UserDefaultsKey.ratingPromptAppLaunchCount.rawValue)
3834

@@ -46,27 +42,24 @@ final class RatingPromptStorage: RatingPromptStorageProtocol, @unchecked Sendabl
4642
userDefaultsManager.synchronize()
4743
}
4844

49-
func recordSignificantEvent() {
50-
lock.lock()
51-
defer { lock.unlock() }
52-
45+
func recordSignificantEvent() async {
5346
let currentCount = userDefaultsManager.getIntValue(for: UserDefaultsKey.ratingPromptSignificantEventCount.rawValue)
5447
userDefaultsManager.set(currentCount + 1, for: UserDefaultsKey.ratingPromptSignificantEventCount.rawValue)
5548
userDefaultsManager.synchronize()
5649
}
5750

58-
func recordPromptShown(for appVersion: String) {
51+
func recordPromptShown(for appVersion: String) async {
5952
userDefaultsManager.set(appVersion, for: UserDefaultsKey.ratingPromptLastPromptedVersion.rawValue)
6053
userDefaultsManager.synchronize()
6154
}
6255

63-
func resetCounters() {
56+
func resetCounters() async {
6457
userDefaultsManager.set(0, for: UserDefaultsKey.ratingPromptAppLaunchCount.rawValue)
6558
userDefaultsManager.set(0, for: UserDefaultsKey.ratingPromptSignificantEventCount.rawValue)
6659
userDefaultsManager.synchronize()
6760
}
6861

69-
func clearAllData() {
62+
func clearAllData() async {
7063
let keys = [
7164
UserDefaultsKey.ratingPromptAppLaunchCount.rawValue,
7265
UserDefaultsKey.ratingPromptFirstLaunchDate.rawValue,

template/Modules/Data/Sources/Services/DefaultRatingPromptPresenter.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@ import StoreKit
77

88
// MARK: - DefaultRatingPromptPresenter
99

10-
public final class DefaultRatingPromptPresenter: RatingPromptPresenterProtocol, @unchecked Sendable {
10+
public actor DefaultRatingPromptPresenter: RatingPromptPresenterProtocol {
1111

1212
private let storeReviewController: any StoreReviewControllerProtocol
1313

1414
public init(storeReviewController: any StoreReviewControllerProtocol) {
1515
self.storeReviewController = storeReviewController
1616
}
1717

18-
@MainActor
1918
public func show() async -> Bool {
2019
return await storeReviewController.requestReview()
2120
}

template/Modules/Domain/Sources/Interfaces/RatingPromptPresenterProtocol.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@
44

55
public protocol RatingPromptPresenterProtocol: Sendable {
66

7-
@MainActor
87
func show() async -> Bool
98
}

template/Modules/Domain/Sources/Interfaces/RatingPromptStorageProtocol.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ import Foundation
44
public protocol RatingPromptStorageProtocol: Sendable {
55

66
/// Retrieves current rating prompt data
7-
func getRatingPromptData() -> RatingPromptData
7+
func getRatingPromptData() async -> RatingPromptData
88

99
/// Increments app launch count and sets first launch date if needed
10-
func recordAppLaunch()
10+
func recordAppLaunch() async
1111

1212
/// Increments significant event count
13-
func recordSignificantEvent()
13+
func recordSignificantEvent() async
1414

1515
/// Records that user was prompted for rating on current version
16-
func recordPromptShown(for appVersion: String)
16+
func recordPromptShown(for appVersion: String) async
1717

1818
/// Resets tracking counters (typically called after prompt is shown)
19-
func resetCounters()
19+
func resetCounters() async
2020

2121
/// Clears all rating prompt related data
22-
func clearAllData()
22+
func clearAllData() async
2323
}

template/Modules/Domain/Sources/UseCases/RequestRatingPromptUseCase.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ public struct RequestRatingPromptUseCase: RequestRatingPromptUseCaseProtocol {
3535

3636
@MainActor
3737
public func callAsFunction(configuration: RatingPromptConfiguration) async -> Bool {
38-
guard shouldShowRatingPromptUseCase(configuration: configuration) else { return false }
38+
guard await shouldShowRatingPromptUseCase(configuration: configuration) else { return false }
3939

4040
let didRequestPrompt = await presenter.show()
4141
guard didRequestPrompt else { return false }
4242

43-
storage.recordPromptShown(for: currentVersion())
43+
await storage.recordPromptShown(for: currentVersion())
4444

4545
if configuration.resetCounterAfterPrompt {
46-
storage.resetCounters()
46+
await storage.resetCounters()
4747
}
4848

4949
return true

template/Modules/Domain/Sources/UseCases/ShouldShowRatingPromptUseCase.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public protocol ShouldShowRatingPromptUseCaseProtocol: Sendable {
99
/// Determines if rating prompt should be shown based on configuration rules
1010
/// - Parameter configuration: Rules for determining eligibility
1111
/// - Returns: True if prompt should be shown
12-
func callAsFunction(configuration: RatingPromptConfiguration) -> Bool
12+
func callAsFunction(configuration: RatingPromptConfiguration) async -> Bool
1313
}
1414

1515
public struct ShouldShowRatingPromptUseCase: ShouldShowRatingPromptUseCaseProtocol, Sendable {
@@ -25,8 +25,8 @@ public struct ShouldShowRatingPromptUseCase: ShouldShowRatingPromptUseCaseProtoc
2525
self.currentVersion = currentVersion
2626
}
2727

28-
public func callAsFunction(configuration: RatingPromptConfiguration) -> Bool {
29-
let data = storage.getRatingPromptData()
28+
public func callAsFunction(configuration: RatingPromptConfiguration) async -> Bool {
29+
let data = await storage.getRatingPromptData()
3030

3131
guard !data.hasBeenPromptedForCurrentVersion(currentVersion) else {
3232
return false

0 commit comments

Comments
 (0)