Skip to content

Commit 7d4a95c

Browse files
committed
Move OrientationMaskStore outside MainActor for Swift concurrency
1 parent b394426 commit 7d4a95c

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

‎BongDaTV/Services/OrientationManager.swift‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@ import Foundation
22
import SwiftUI
33
import UIKit
44

5+
private enum OrientationMaskStore {
6+
private static let lock = NSLock()
7+
private static var mask: UIInterfaceOrientationMask = .portrait
8+
9+
static var current: UIInterfaceOrientationMask {
10+
get {
11+
lock.lock()
12+
defer { lock.unlock() }
13+
return mask
14+
}
15+
set {
16+
lock.lock()
17+
defer { lock.unlock() }
18+
mask = newValue
19+
}
20+
}
21+
}
22+
523
final class AppDelegate: NSObject, UIApplicationDelegate {
624
func application(
725
_ application: UIApplication,
@@ -15,20 +33,9 @@ final class AppDelegate: NSObject, UIApplicationDelegate {
1533
final class OrientationManager: ObservableObject {
1634
static let shared = OrientationManager()
1735

18-
private static let maskLock = NSLock()
19-
private static var _allowedMask: UIInterfaceOrientationMask = .portrait
20-
2136
nonisolated static var currentAllowedMask: UIInterfaceOrientationMask {
22-
get {
23-
maskLock.lock()
24-
defer { maskLock.unlock() }
25-
return _allowedMask
26-
}
27-
set {
28-
maskLock.lock()
29-
defer { maskLock.unlock() }
30-
_allowedMask = newValue
31-
}
37+
get { OrientationMaskStore.current }
38+
set { OrientationMaskStore.current = newValue }
3239
}
3340

3441
@Published private(set) var isLandscape: Bool = false

0 commit comments

Comments
 (0)