mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:02:10 +00:00
Swift 6 migration for NSE (#5608)
* swift 6 support for NSE and concurrency safe implementations for it * enforcing required Sendable conformance for swift 6 migration in NSE * use Mutex to access the string builder cache * use an async stream to update timeline items diffs * fix for Sendable appHooks
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Synchronization
|
||||
|
||||
public extension Bundle {
|
||||
/// The top-level bundle that contains the entire app.
|
||||
@@ -24,12 +25,12 @@ public extension Bundle {
|
||||
|
||||
// MARK: - Localisation
|
||||
|
||||
/// Overrides `Bundle.app.preferredLocalizations` for testing translations.
|
||||
static var overrideLocalizations: [String]?
|
||||
|
||||
private static let cacheDispatchQueue = DispatchQueue(label: "io.element.elementx.localization_bundle_cache")
|
||||
private static var cachedBundles = [String: Bundle]()
|
||||
|
||||
/// Overrides `Bundle.app.preferredLocalizations` for testing translations since this is
|
||||
/// only for testing, and is changed at runtime only in tests, it's fine to keep as `nonisolated(unsafe)`
|
||||
nonisolated(unsafe) static var overrideLocalizations: [String]?
|
||||
|
||||
private static let cachedBundles = Mutex<[String: Bundle]>([:])
|
||||
|
||||
/// Get an lproj language bundle from the receiver bundle.
|
||||
/// - Parameter language: The language to try to load.
|
||||
/// - Returns: The lproj bundle if found otherwise nil.
|
||||
@@ -37,32 +38,25 @@ public extension Bundle {
|
||||
if let bundle = cachedValue(forKey: language) {
|
||||
return bundle
|
||||
}
|
||||
|
||||
|
||||
guard let lprojURL = Bundle.app.url(forResource: language, withExtension: "lproj") else {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
let bundle = Bundle(url: lprojURL)
|
||||
|
||||
|
||||
cacheValue(bundle, forKey: language)
|
||||
|
||||
|
||||
return bundle
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
|
||||
private static func cacheValue(_ value: Bundle?, forKey key: String) {
|
||||
cacheDispatchQueue.sync {
|
||||
cachedBundles[key] = value
|
||||
}
|
||||
cachedBundles.withLock { $0[key] = value }
|
||||
}
|
||||
|
||||
|
||||
private static func cachedValue(forKey key: String) -> Bundle? {
|
||||
var result: Bundle?
|
||||
cacheDispatchQueue.sync {
|
||||
result = cachedBundles[key]
|
||||
}
|
||||
|
||||
return result
|
||||
cachedBundles.withLock { $0[key] }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user