Skip to content

Commit 3ccecaf

Browse files
committed
review pass 2
1 parent 4ab7446 commit 3ccecaf

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

FirebaseRemoteConfig/SwiftNew/RemoteConfig.swift

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -241,36 +241,27 @@ open class RemoteConfig: NSObject, NSFastEnumeration {
241241
}
242242

243243
/// Last successful fetch completion time.
244-
@objc public var lastFetchTime: Date? {
245-
var fetchTime: Date?
244+
@objc public var lastFetchTime: Date {
246245
queue.sync {
247246
let lastFetchTimeInterval = self.settings.lastFetchTimeInterval
248-
if lastFetchTimeInterval > 0 {
249-
fetchTime = Date(timeIntervalSince1970: lastFetchTimeInterval)
250-
}
247+
return Date(timeIntervalSince1970: lastFetchTimeInterval)
251248
}
252-
return fetchTime
253249
}
254250

255251
/// Last fetch status. The status can be any enumerated value from `RemoteConfigFetchStatus`.
256252
@objc public var lastFetchStatus: RemoteConfigFetchStatus {
257-
var currentStatus: RemoteConfigFetchStatus = .noFetchYet
258253
queue.sync {
259-
currentStatus = self.configFetch.settings.lastFetchStatus
254+
self.configFetch.settings.lastFetchStatus
260255
}
261-
return currentStatus
262256
}
263257

264258
/// Config settings are custom settings.
265259
@objc public var configSettings: RemoteConfigSettings {
266260
get {
267261
// These properties *must* be accessed and returned on the lock queue
268262
// to ensure thread safety.
269-
var minimumFetchInterval: TimeInterval = ConfigConstants.defaultMinimumFetchInterval
270-
var fetchTimeout: TimeInterval = ConfigConstants.httpDefaultConnectionTimeout
271-
queue.sync {
272-
minimumFetchInterval = self.settings.minimumFetchInterval
273-
fetchTimeout = self.settings.fetchTimeout
263+
let (minimumFetchInterval, fetchTimeout) = queue.sync {
264+
(self.settings.minimumFetchInterval, self.settings.fetchTimeout)
274265
}
275266

276267
RCLog.debug("I-RCN000066",
@@ -279,16 +270,18 @@ open class RemoteConfig: NSObject, NSFastEnumeration {
279270
let settings = RemoteConfigSettings()
280271
settings.minimumFetchInterval = minimumFetchInterval
281272
settings.fetchTimeout = fetchTimeout
273+
274+
/// The NSURLSession needs to be recreated whenever the fetch timeout may be updated.
275+
configFetch.recreateNetworkSession()
282276
RCLog.debug("I-RCN987366",
283277
"Successfully read configSettings. Minimum Fetch Interval: " +
284278
"\(minimumFetchInterval), Fetch timeout: \(fetchTimeout)")
285279
return settings
286280
}
287281
set {
288282
queue.async {
289-
let configSettings = newValue
290-
self.settings.minimumFetchInterval = configSettings.minimumFetchInterval
291-
self.settings.fetchTimeout = configSettings.fetchTimeout
283+
self.settings.minimumFetchInterval = newValue.minimumFetchInterval
284+
self.settings.fetchTimeout = newValue.fetchTimeout
292285

293286
/// The NSURLSession needs to be recreated whenever the fetch timeout may be updated.
294287
self.configFetch.recreateNetworkSession()
@@ -413,7 +406,7 @@ open class RemoteConfig: NSObject, NSFastEnumeration {
413406
/// - Parameter completionHandler: Initialization complete callback with error parameter.
414407
@objc public func ensureInitialized(completionHandler: @escaping (Error?) -> Void) {
415408
DispatchQueue.global(qos: .utility).async { [weak self] in
416-
guard let self = self else { return }
409+
guard let self else { return }
417410
let initializationSuccess = self.configContent.initializationSuccessful()
418411
let error = initializationSuccess ? nil :
419412
NSError(
@@ -435,7 +428,7 @@ open class RemoteConfig: NSObject, NSFastEnumeration {
435428

436429
private func callListeners(key: String, config: [String: RemoteConfigValue]) {
437430
queue.async { [weak self] in
438-
guard let self = self else { return }
431+
guard let self else { return }
439432
for listener in self.listeners {
440433
listener(key, config)
441434
}
@@ -564,7 +557,7 @@ open class RemoteConfig: NSObject, NSFastEnumeration {
564557
((RemoteConfigFetchAndActivateStatus, Error?) -> Void)? =
565558
nil) {
566559
fetch { [weak self] fetchStatus, error in
567-
guard let self = self else { return }
560+
guard let self else { return }
568561
// Fetch completed. We are being called on the main queue.
569562
// If fetch is successful, try to activate the fetched config
570563
if fetchStatus == .success, error == nil {
@@ -611,7 +604,7 @@ open class RemoteConfig: NSObject, NSFastEnumeration {
611604
/// - Parameter completion Activate operation callback with changed and error parameters.
612605
@objc public func activate(completion: ((Bool, Error?) -> Void)? = nil) {
613606
queue.async { [weak self] in
614-
guard let self = self else {
607+
guard let self else {
615608
let error = NSError(
616609
domain: ConfigConstants.remoteConfigErrorDomain,
617610
code: RemoteConfigError.internalError.rawValue,
@@ -816,7 +809,7 @@ open class RemoteConfig: NSObject, NSFastEnumeration {
816809
let defaults = defaults ?? [String: Any]()
817810
let fullyQualifiedNamespace = self.fullyQualifiedNamespace(FIRNamespace)
818811
queue.async { [weak self] in
819-
guard let self = self else { return }
812+
guard let self else { return }
820813

821814
self.configContent.copy(fromDictionary: [fullyQualifiedNamespace: defaults],
822815
toSource: .default,

0 commit comments

Comments
 (0)