From 8e5d57ed87057cd7b0e4e8f474d9e78f73eb85f7 Mon Sep 17 00:00:00 2001 From: Nick Cooke <36927374+ncooke3@users.noreply.github.com> Date: Tue, 23 Apr 2024 17:56:27 -0400 Subject: [PATCH] [UserDefaults] Remove delayed synchronization (#148) * [UserDefaults] Remove delayed synchronization * Bump podspec * Revert "[UserDefaults] Remove delayed synchronization" This reverts commit dce15d170f9ce25af9ed7ae2c6c74b3f056a088e. * Revert "Revert "[UserDefaults] Remove delayed synchronization"" This reverts commit 0eacd37134fe8fb096040e2996e24461d9413608. * Remove unused variable * Add changelog entry --- CHANGELOG.md | 4 ++++ GoogleUtilities.podspec | 2 +- .../UserDefaults/GULUserDefaults.m | 21 ++----------------- 3 files changed, 7 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2970a68..7596a35f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 7.13.2 +- Remove synchronization delay for `GULUserDefaults` to better match + `NSUserDefaults` behavior. (#148) + # 7.13.1 (SwiftPM Only) - Attempt to fix validation error due to invalid module name. (#146) diff --git a/GoogleUtilities.podspec b/GoogleUtilities.podspec index f9141e81..f0a03ab0 100644 --- a/GoogleUtilities.podspec +++ b/GoogleUtilities.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'GoogleUtilities' - s.version = '7.13.0' + s.version = '7.13.2' s.summary = 'Google Utilities for Apple platform SDKs' s.description = <<-DESC diff --git a/GoogleUtilities/UserDefaults/GULUserDefaults.m b/GoogleUtilities/UserDefaults/GULUserDefaults.m index 1640d6ed..6c45048a 100644 --- a/GoogleUtilities/UserDefaults/GULUserDefaults.m +++ b/GoogleUtilities/UserDefaults/GULUserDefaults.m @@ -18,8 +18,6 @@ NS_ASSUME_NONNULL_BEGIN -static NSTimeInterval const kGULSynchronizeInterval = 1.0; - static NSString *const kGULLogFormat = @"I-GUL%06ld"; static GULLoggerService kGULLogUserDefaultsService = @"[GoogleUtilities/UserDefaults]"; @@ -107,7 +105,7 @@ - (void)setObject:(nullable id)value forKey:(NSString *)defaultName { } if (!value) { CFPreferencesSetAppValue((__bridge CFStringRef)key, NULL, _appNameRef); - [self scheduleSynchronize]; + [self synchronize]; return; } BOOL isAcceptableValue = @@ -124,7 +122,7 @@ - (void)setObject:(nullable id)value forKey:(NSString *)defaultName { } CFPreferencesSetAppValue((__bridge CFStringRef)key, (__bridge CFStringRef)value, _appNameRef); - [self scheduleSynchronize]; + [self synchronize]; } - (void)removeObjectForKey:(NSString *)key { @@ -193,21 +191,6 @@ - (void)synchronize { } } -#pragma mark - Private methods - -- (void)scheduleSynchronize { - // Synchronize data using a timer so that multiple set... calls can be coalesced under one - // synchronize. - [NSObject cancelPreviousPerformRequestsWithTarget:self - selector:@selector(synchronize) - object:nil]; - // This method may be called on multiple queues (due to set... methods can be called on any queue) - // synchronize can be scheduled on different queues, so make sure that it does not crash. If this - // instance goes away, self will be released also, no one will retain it and the schedule won't be - // called. - [self performSelector:@selector(synchronize) withObject:nil afterDelay:kGULSynchronizeInterval]; -} - @end NS_ASSUME_NONNULL_END