From 88fff5dedcc28d5bae1526e363ed8d3d385a68b9 Mon Sep 17 00:00:00 2001 From: Markus Kauppila Date: Sun, 23 Nov 2014 15:28:23 +0200 Subject: [PATCH 01/11] Bump minimum deployment version of iOS to 7.0 --- README.md | 2 +- TMCache.podspec | 2 +- tests/TMCache.xcodeproj/project.pbxproj | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 2d4cb9d..d7088ae 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ Add [TMCache](http://cocoapods.org/?q=name%3ATMCache) to your `Podfile` and run ## Requirements ## -__TMCache__ requires iOS 5.0 or OS X 10.7 and greater. +__TMCache__ requires iOS 7.0 or OS X 10.7 and greater. ## Contact ## diff --git a/TMCache.podspec b/TMCache.podspec index 65dac43..a930ac7 100644 --- a/TMCache.podspec +++ b/TMCache.podspec @@ -11,6 +11,6 @@ Pod::Spec.new do |s| s.frameworks = 'Foundation' s.ios.weak_frameworks = 'UIKit' s.osx.weak_frameworks = 'AppKit' - s.ios.deployment_target = '5.0' + s.ios.deployment_target = '7.0' s.osx.deployment_target = '10.7' end diff --git a/tests/TMCache.xcodeproj/project.pbxproj b/tests/TMCache.xcodeproj/project.pbxproj index e340a5e..40afbba 100644 --- a/tests/TMCache.xcodeproj/project.pbxproj +++ b/tests/TMCache.xcodeproj/project.pbxproj @@ -202,7 +202,7 @@ name = TMCacheTests; productName = TMCacheTests; productReference = D07F1ED2171AFB7A001DBA02 /* TMCacheTests.octest */; - productType = "com.apple.product-type.bundle"; + productType = "com.apple.product-type.bundle.ocunit-test"; }; /* End PBXNativeTarget section */ @@ -328,7 +328,7 @@ GCC_WARN_PEDANTIC = NO; GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 6.1; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -354,7 +354,7 @@ GCC_WARN_PEDANTIC = NO; GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 6.1; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; SDKROOT = iphoneos; @@ -370,7 +370,7 @@ GCC_PREFIX_HEADER = "TMCache/TMCache-Prefix.pch"; GCC_WARN_PEDANTIC = YES; INFOPLIST_FILE = "TMCache/TMCache-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 6.1; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; @@ -383,7 +383,7 @@ GCC_PREFIX_HEADER = "TMCache/TMCache-Prefix.pch"; GCC_WARN_PEDANTIC = YES; INFOPLIST_FILE = "TMCache/TMCache-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 6.1; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; From 1835c0306d8a815e206894349c2d0b0aef34c97d Mon Sep 17 00:00:00 2001 From: Markus Kauppila Date: Sun, 23 Nov 2014 15:42:56 +0200 Subject: [PATCH 02/11] Fix obsolete usage of OS_OBJECT_USE_OBJC LibSystem objects are handled by ARC nowadays. --- TMCache/TMCache.m | 48 ----------------------------------------- TMCache/TMDiskCache.m | 36 ------------------------------- TMCache/TMMemoryCache.m | 41 ----------------------------------- 3 files changed, 125 deletions(-) diff --git a/TMCache/TMCache.m b/TMCache/TMCache.m index afba609..ba93d69 100644 --- a/TMCache/TMCache.m +++ b/TMCache/TMCache.m @@ -4,25 +4,13 @@ NSString * const TMCacheSharedName = @"TMCacheShared"; @interface TMCache () -#if OS_OBJECT_USE_OBJC @property (strong, nonatomic) dispatch_queue_t queue; -#else -@property (assign, nonatomic) dispatch_queue_t queue; -#endif @end @implementation TMCache #pragma mark - Initialization - -#if !OS_OBJECT_USE_OBJC -- (void)dealloc -{ - dispatch_release(_queue); - _queue = nil; -} -#endif - - (instancetype)initWithName:(NSString *)name { return [self initWithName:name rootPath:[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0]]; @@ -151,10 +139,6 @@ - (void)setObject:(id )object forKey:(NSString *)key block:(TMCacheObj if (strongSelf) block(strongSelf, key, object); }); - - #if !OS_OBJECT_USE_OBJC - dispatch_release(group); - #endif } } @@ -191,10 +175,6 @@ - (void)removeObjectForKey:(NSString *)key block:(TMCacheObjectBlock)block if (strongSelf) block(strongSelf, key, nil); }); - - #if !OS_OBJECT_USE_OBJC - dispatch_release(group); - #endif } } @@ -228,10 +208,6 @@ - (void)removeAllObjects:(TMCacheBlock)block if (strongSelf) block(strongSelf); }); - - #if !OS_OBJECT_USE_OBJC - dispatch_release(group); - #endif } } @@ -268,10 +244,6 @@ - (void)trimToDate:(NSDate *)date block:(TMCacheBlock)block if (strongSelf) block(strongSelf); }); - - #if !OS_OBJECT_USE_OBJC - dispatch_release(group); - #endif } } @@ -306,10 +278,6 @@ - (id)objectForKey:(NSString *)key dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); - #if !OS_OBJECT_USE_OBJC - dispatch_release(semaphore); - #endif - return objectForKey; } @@ -325,10 +293,6 @@ - (void)setObject:(id )object forKey:(NSString *)key }]; dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); - - #if !OS_OBJECT_USE_OBJC - dispatch_release(semaphore); - #endif } - (void)removeObjectForKey:(NSString *)key @@ -343,10 +307,6 @@ - (void)removeObjectForKey:(NSString *)key }]; dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); - - #if !OS_OBJECT_USE_OBJC - dispatch_release(semaphore); - #endif } - (void)trimToDate:(NSDate *)date @@ -361,10 +321,6 @@ - (void)trimToDate:(NSDate *)date }]; dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); - - #if !OS_OBJECT_USE_OBJC - dispatch_release(semaphore); - #endif } - (void)removeAllObjects @@ -376,10 +332,6 @@ - (void)removeAllObjects }]; dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); - - #if !OS_OBJECT_USE_OBJC - dispatch_release(semaphore); - #endif } @end diff --git a/TMCache/TMDiskCache.m b/TMCache/TMDiskCache.m index 4329e05..99688ba 100644 --- a/TMCache/TMDiskCache.m +++ b/TMCache/TMDiskCache.m @@ -694,10 +694,6 @@ - (void)enumerateObjectsWithBlock:(TMDiskCacheObjectBlock)block completionBlock: dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); - #if !OS_OBJECT_USE_OBJC - dispatch_release(semaphore); - #endif - return objectForKey; } @@ -717,10 +713,6 @@ - (NSURL *)fileURLForKey:(NSString *)key dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); - #if !OS_OBJECT_USE_OBJC - dispatch_release(semaphore); - #endif - return fileURLForKey; } @@ -736,10 +728,6 @@ - (void)setObject:(id )object forKey:(NSString *)key }]; dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); - - #if !OS_OBJECT_USE_OBJC - dispatch_release(semaphore); - #endif } - (void)removeObjectForKey:(NSString *)key @@ -754,10 +742,6 @@ - (void)removeObjectForKey:(NSString *)key }]; dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); - - #if !OS_OBJECT_USE_OBJC - dispatch_release(semaphore); - #endif } - (void)trimToSize:(NSUInteger)byteCount @@ -769,10 +753,6 @@ - (void)trimToSize:(NSUInteger)byteCount }]; dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); - - #if !OS_OBJECT_USE_OBJC - dispatch_release(semaphore); - #endif } - (void)trimToDate:(NSDate *)date @@ -792,10 +772,6 @@ - (void)trimToDate:(NSDate *)date }]; dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); - - #if !OS_OBJECT_USE_OBJC - dispatch_release(semaphore); - #endif } - (void)trimToSizeByDate:(NSUInteger)byteCount @@ -807,10 +783,6 @@ - (void)trimToSizeByDate:(NSUInteger)byteCount }]; dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); - - #if !OS_OBJECT_USE_OBJC - dispatch_release(semaphore); - #endif } - (void)removeAllObjects @@ -822,10 +794,6 @@ - (void)removeAllObjects }]; dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); - - #if !OS_OBJECT_USE_OBJC - dispatch_release(semaphore); - #endif } - (void)enumerateObjectsWithBlock:(TMDiskCacheObjectBlock)block @@ -840,10 +808,6 @@ - (void)enumerateObjectsWithBlock:(TMDiskCacheObjectBlock)block }]; dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); - - #if !OS_OBJECT_USE_OBJC - dispatch_release(semaphore); - #endif } #pragma mark - Public Thread Safe Accessors - diff --git a/TMCache/TMMemoryCache.m b/TMCache/TMMemoryCache.m index 66972cc..c3f5065 100644 --- a/TMCache/TMMemoryCache.m +++ b/TMCache/TMMemoryCache.m @@ -3,11 +3,7 @@ NSString * const TMMemoryCachePrefix = @"com.tumblr.TMMemoryCache"; @interface TMMemoryCache () -#if OS_OBJECT_USE_OBJC @property (strong, nonatomic) dispatch_queue_t queue; -#else -@property (assign, nonatomic) dispatch_queue_t queue; -#endif @property (strong, nonatomic) NSMutableDictionary *dictionary; @property (strong, nonatomic) NSMutableDictionary *dates; @property (strong, nonatomic) NSMutableDictionary *costs; @@ -32,11 +28,6 @@ @implementation TMMemoryCache - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; - - #if !OS_OBJECT_USE_OBJC - dispatch_release(_queue); - _queue = nil; - #endif } - (id)init @@ -475,10 +466,6 @@ - (id)objectForKey:(NSString *)key dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); - #if !OS_OBJECT_USE_OBJC - dispatch_release(semaphore); - #endif - return objectForKey; } @@ -499,10 +486,6 @@ - (void)setObject:(id)object forKey:(NSString *)key withCost:(NSUInteger)cost }]; dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); - - #if !OS_OBJECT_USE_OBJC - dispatch_release(semaphore); - #endif } - (void)removeObjectForKey:(NSString *)key @@ -517,10 +500,6 @@ - (void)removeObjectForKey:(NSString *)key }]; dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); - - #if !OS_OBJECT_USE_OBJC - dispatch_release(semaphore); - #endif } - (void)trimToDate:(NSDate *)date @@ -540,10 +519,6 @@ - (void)trimToDate:(NSDate *)date }]; dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); - - #if !OS_OBJECT_USE_OBJC - dispatch_release(semaphore); - #endif } - (void)trimToCost:(NSUInteger)cost @@ -555,10 +530,6 @@ - (void)trimToCost:(NSUInteger)cost }]; dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); - - #if !OS_OBJECT_USE_OBJC - dispatch_release(semaphore); - #endif } - (void)trimToCostByDate:(NSUInteger)cost @@ -570,10 +541,6 @@ - (void)trimToCostByDate:(NSUInteger)cost }]; dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); - - #if !OS_OBJECT_USE_OBJC - dispatch_release(semaphore); - #endif } - (void)removeAllObjects @@ -585,10 +552,6 @@ - (void)removeAllObjects }]; dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); - - #if !OS_OBJECT_USE_OBJC - dispatch_release(semaphore); - #endif } - (void)enumerateObjectsWithBlock:(TMMemoryCacheObjectBlock)block @@ -603,10 +566,6 @@ - (void)enumerateObjectsWithBlock:(TMMemoryCacheObjectBlock)block }]; dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); - - #if !OS_OBJECT_USE_OBJC - dispatch_release(semaphore); - #endif } #pragma mark - Public Thread Safe Accessors - From 1487eec1f9700df01ad7bea6442a2ef3bb1be991 Mon Sep 17 00:00:00 2001 From: Markus Kauppila Date: Sun, 23 Nov 2014 15:54:21 +0200 Subject: [PATCH 03/11] Add NS_DESIGNATED_INITIALIZER markers --- TMCache/TMCache.h | 2 +- TMCache/TMDiskCache.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/TMCache/TMCache.h b/TMCache/TMCache.h index 7c2d10a..d1655d3 100644 --- a/TMCache/TMCache.h +++ b/TMCache/TMCache.h @@ -82,7 +82,7 @@ typedef void (^TMCacheObjectBlock)(TMCache *cache, NSString *key, id object); @param rootPath The path of the cache on disk. @result A new cache with the specified name. */ -- (instancetype)initWithName:(NSString *)name rootPath:(NSString *)rootPath; +- (instancetype)initWithName:(NSString *)name rootPath:(NSString *)rootPath NS_DESIGNATED_INITIALIZER; #pragma mark - /// @name Asynchronous Methods diff --git a/TMCache/TMDiskCache.h b/TMCache/TMDiskCache.h index 7bb9e05..66e67e9 100644 --- a/TMCache/TMDiskCache.h +++ b/TMCache/TMDiskCache.h @@ -159,7 +159,7 @@ typedef void (^TMDiskCacheObjectBlock)(TMDiskCache *cache, NSString *key, id Date: Sun, 23 Nov 2014 15:59:41 +0200 Subject: [PATCH 04/11] Use the modern accessor syntax with arrays and dictionaries --- TMCache/TMCache.m | 3 ++- TMCache/TMDiskCache.m | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/TMCache/TMCache.m b/TMCache/TMCache.m index ba93d69..f43d34b 100644 --- a/TMCache/TMCache.m +++ b/TMCache/TMCache.m @@ -13,7 +13,8 @@ @implementation TMCache - (instancetype)initWithName:(NSString *)name { - return [self initWithName:name rootPath:[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0]]; + return [self initWithName:name + rootPath:[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]]; } - (instancetype)initWithName:(NSString *)name rootPath:(NSString *)rootPath diff --git a/TMCache/TMDiskCache.m b/TMCache/TMDiskCache.m index 99688ba..fa3b5e6 100644 --- a/TMCache/TMDiskCache.m +++ b/TMCache/TMDiskCache.m @@ -40,7 +40,8 @@ @implementation TMDiskCache - (instancetype)initWithName:(NSString *)name { - return [self initWithName:name rootPath:[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0]]; + return [self initWithName:name + rootPath:[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]]; } - (instancetype)initWithName:(NSString *)name rootPath:(NSString *)rootPath @@ -264,13 +265,13 @@ - (void)initializeDiskProperties NSDictionary *dictionary = [fileURL resourceValuesForKeys:keys error:&error]; TMDiskCacheError(error); - NSDate *date = [dictionary objectForKey:NSURLContentModificationDateKey]; + NSDate *date = dictionary[NSURLContentModificationDateKey]; if (date && key) - [_dates setObject:date forKey:key]; + _dates[key] = date; - NSNumber *fileSize = [dictionary objectForKey:NSURLTotalFileAllocatedSizeKey]; + NSNumber *fileSize = dictionary[NSURLTotalFileAllocatedSizeKey]; if (fileSize) { - [_sizes setObject:fileSize forKey:key]; + _sizes[key] = fileSize; byteCount += [fileSize unsignedIntegerValue]; } } @@ -294,7 +295,7 @@ - (BOOL)setFileModificationDate:(NSDate *)date forURL:(NSURL *)fileURL if (success) { NSString *key = [self keyForEncodedFileURL:fileURL]; if (key) { - [_dates setObject:date forKey:key]; + _dates[key] = date; } } @@ -316,7 +317,7 @@ - (BOOL)removeFileAndExecuteBlocksForKey:(NSString *)key [TMDiskCache emptyTrash]; - NSNumber *byteSize = [_sizes objectForKey:key]; + NSNumber *byteSize = _sizes[key]; if (byteSize) self.byteCount = _byteCount - [byteSize unsignedIntegerValue]; // atomic @@ -364,7 +365,7 @@ - (void)trimDiskToDate:(NSDate *)trimDate NSArray *keysSortedByDate = [_dates keysSortedByValueUsingSelector:@selector(compare:)]; for (NSString *key in keysSortedByDate) { // oldest files first - NSDate *accessDate = [_dates objectForKey:key]; + NSDate *accessDate = _dates[key]; if (!accessDate) continue; @@ -479,9 +480,9 @@ - (void)setObject:(id )object forKey:(NSString *)key block:(TMDiskCach NSDictionary *values = [fileURL resourceValuesForKeys:@[ NSURLTotalFileAllocatedSizeKey ] error:&error]; TMDiskCacheError(error); - NSNumber *diskFileSize = [values objectForKey:NSURLTotalFileAllocatedSizeKey]; + NSNumber *diskFileSize = values[NSURLTotalFileAllocatedSizeKey]; if (diskFileSize) { - [strongSelf->_sizes setObject:diskFileSize forKey:key]; + strongSelf->_sizes[key] = diskFileSize; strongSelf.byteCount = strongSelf->_byteCount + [diskFileSize unsignedIntegerValue]; // atomic } From 9d761ee1b56532bfee84361676709dc2abaf6a2a Mon Sep 17 00:00:00 2001 From: Markus Kauppila Date: Sun, 23 Nov 2014 16:02:12 +0200 Subject: [PATCH 05/11] Fix return type of TMMemoryCache's initializer --- TMCache/TMMemoryCache.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TMCache/TMMemoryCache.m b/TMCache/TMMemoryCache.m index c3f5065..b18061d 100644 --- a/TMCache/TMMemoryCache.m +++ b/TMCache/TMMemoryCache.m @@ -30,7 +30,7 @@ - (void)dealloc [[NSNotificationCenter defaultCenter] removeObserver:self]; } -- (id)init +- (instancetype)init { if (self = [super init]) { NSString *queueName = [[NSString alloc] initWithFormat:@"%@.%p", TMMemoryCachePrefix, self]; From 74109f0cbf6c77ce6d0dac44c905276ad8ffc071 Mon Sep 17 00:00:00 2001 From: Markus Kauppila Date: Sun, 23 Nov 2014 16:16:33 +0200 Subject: [PATCH 06/11] Delete obsolete minimum required OS version checks --- TMCache/TMDiskCache.m | 16 +++++++--------- TMCache/TMMemoryCache.m | 6 ------ 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/TMCache/TMDiskCache.m b/TMCache/TMDiskCache.m index fa3b5e6..ea74662 100644 --- a/TMCache/TMDiskCache.m +++ b/TMCache/TMDiskCache.m @@ -4,15 +4,13 @@ [[NSString stringWithUTF8String:__FILE__] lastPathComponent], \ __LINE__, [error localizedDescription]); } -#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0 - #define TMCacheStartBackgroundTask() UIBackgroundTaskIdentifier taskID = UIBackgroundTaskInvalid; \ - taskID = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ \ - [[UIApplication sharedApplication] endBackgroundTask:taskID]; }]; - #define TMCacheEndBackgroundTask() [[UIApplication sharedApplication] endBackgroundTask:taskID]; -#else - #define TMCacheStartBackgroundTask() - #define TMCacheEndBackgroundTask() -#endif +#define TMCacheStartBackgroundTask() \ + UIBackgroundTaskIdentifier taskID = UIBackgroundTaskInvalid; \ + taskID = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ \ + [[UIApplication sharedApplication] endBackgroundTask:taskID]; \ + }]; +#define TMCacheEndBackgroundTask() \ + [[UIApplication sharedApplication] endBackgroundTask:taskID]; NSString * const TMDiskCachePrefix = @"com.tumblr.TMDiskCache"; NSString * const TMDiskCacheSharedName = @"TMDiskCacheShared"; diff --git a/TMCache/TMMemoryCache.m b/TMCache/TMMemoryCache.m index b18061d..d92ac34 100644 --- a/TMCache/TMMemoryCache.m +++ b/TMCache/TMMemoryCache.m @@ -58,14 +58,12 @@ - (instancetype)init _removeAllObjectsOnMemoryWarning = YES; _removeAllObjectsOnEnteringBackground = YES; - #if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0 for (NSString *name in @[UIApplicationDidReceiveMemoryWarningNotification, UIApplicationDidEnterBackgroundNotification]) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didObserveApocalypticNotification:) name:name object:[UIApplication sharedApplication]]; } - #endif } return self; } @@ -86,8 +84,6 @@ + (instancetype)sharedCache - (void)didObserveApocalypticNotification:(NSNotification *)notification { - #if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0 - if ([[notification name] isEqualToString:UIApplicationDidReceiveMemoryWarningNotification]) { if (self.removeAllObjectsOnMemoryWarning) [self removeAllObjects:nil]; @@ -117,8 +113,6 @@ - (void)didObserveApocalypticNotification:(NSNotification *)notification strongSelf->_didEnterBackgroundBlock(strongSelf); }); } - - #endif } - (void)removeObjectAndExecuteBlocksForKey:(NSString *)key From 23706dd585255cfc07ba5d232e358b6e9808ab18 Mon Sep 17 00:00:00 2001 From: Markus Kauppila Date: Sun, 23 Nov 2014 16:25:20 +0200 Subject: [PATCH 07/11] Add static to locally used NSString constants --- TMCache/TMCache.m | 4 ++-- TMCache/TMDiskCache.m | 4 ++-- TMCache/TMMemoryCache.m | 2 +- tests/TMCacheTests/TMCacheTests.m | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/TMCache/TMCache.m b/TMCache/TMCache.m index f43d34b..65fdaac 100644 --- a/TMCache/TMCache.m +++ b/TMCache/TMCache.m @@ -1,7 +1,7 @@ #import "TMCache.h" -NSString * const TMCachePrefix = @"com.tumblr.TMCache"; -NSString * const TMCacheSharedName = @"TMCacheShared"; +static NSString * const TMCachePrefix = @"com.tumblr.TMCache"; +static NSString * const TMCacheSharedName = @"TMCacheShared"; @interface TMCache () @property (strong, nonatomic) dispatch_queue_t queue; diff --git a/TMCache/TMDiskCache.m b/TMCache/TMDiskCache.m index ea74662..2e3afea 100644 --- a/TMCache/TMDiskCache.m +++ b/TMCache/TMDiskCache.m @@ -12,8 +12,8 @@ #define TMCacheEndBackgroundTask() \ [[UIApplication sharedApplication] endBackgroundTask:taskID]; -NSString * const TMDiskCachePrefix = @"com.tumblr.TMDiskCache"; -NSString * const TMDiskCacheSharedName = @"TMDiskCacheShared"; +static NSString * const TMDiskCachePrefix = @"com.tumblr.TMDiskCache"; +static NSString * const TMDiskCacheSharedName = @"TMDiskCacheShared"; @interface TMDiskCache () @property (assign) NSUInteger byteCount; diff --git a/TMCache/TMMemoryCache.m b/TMCache/TMMemoryCache.m index d92ac34..33a771c 100644 --- a/TMCache/TMMemoryCache.m +++ b/TMCache/TMMemoryCache.m @@ -1,6 +1,6 @@ #import "TMMemoryCache.h" -NSString * const TMMemoryCachePrefix = @"com.tumblr.TMMemoryCache"; +static NSString * const TMMemoryCachePrefix = @"com.tumblr.TMMemoryCache"; @interface TMMemoryCache () @property (strong, nonatomic) dispatch_queue_t queue; diff --git a/tests/TMCacheTests/TMCacheTests.m b/tests/TMCacheTests/TMCacheTests.m index 8122891..39452ef 100644 --- a/tests/TMCacheTests/TMCacheTests.m +++ b/tests/TMCacheTests/TMCacheTests.m @@ -1,8 +1,8 @@ #import "TMCacheTests.h" #import "TMCache.h" -NSString * const TMCacheTestName = @"TMCacheTest"; NSTimeInterval TMCacheTestBlockTimeout = 5.0; +static NSString * const TMCacheTestName = @"TMCacheTest"; @interface TMCacheTests () @property (strong, nonatomic) TMCache *cache; From 02652ccb4bc9902a1a1fa0969d58c547bd81ce63 Mon Sep 17 00:00:00 2001 From: Markus Kauppila Date: Sun, 23 Nov 2014 16:26:41 +0200 Subject: [PATCH 08/11] Make TMCacheTestBlockTimeout constant --- tests/TMCacheTests/TMCacheTests.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/TMCacheTests/TMCacheTests.m b/tests/TMCacheTests/TMCacheTests.m index 39452ef..2673159 100644 --- a/tests/TMCacheTests/TMCacheTests.m +++ b/tests/TMCacheTests/TMCacheTests.m @@ -1,8 +1,8 @@ #import "TMCacheTests.h" #import "TMCache.h" -NSTimeInterval TMCacheTestBlockTimeout = 5.0; static NSString * const TMCacheTestName = @"TMCacheTest"; +static const NSTimeInterval TMCacheTestBlockTimeout = 5.0; @interface TMCacheTests () @property (strong, nonatomic) TMCache *cache; From 8932980868ca886e5dd779c1b5aa0023629c0be2 Mon Sep 17 00:00:00 2001 From: Markus Kauppila Date: Sun, 23 Nov 2014 17:30:43 +0200 Subject: [PATCH 09/11] Fix compiler warnings from tests --- tests/TMCacheTests/TMCacheTests.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/TMCacheTests/TMCacheTests.m b/tests/TMCacheTests/TMCacheTests.m index 2673159..a234bca 100644 --- a/tests/TMCacheTests/TMCacheTests.m +++ b/tests/TMCacheTests/TMCacheTests.m @@ -181,8 +181,8 @@ - (void)testOneThousandAndOneWrites dispatch_group_t group = dispatch_group_create(); for (NSUInteger i = 0; i < max; i++) { - NSString *key = [[NSString alloc] initWithFormat:@"key %d", i]; - NSString *obj = [[NSString alloc] initWithFormat:@"obj %d", i]; + NSString *key = [[NSString alloc] initWithFormat:@"key %lu", (unsigned long)i]; + NSString *obj = [[NSString alloc] initWithFormat:@"obj %lu", (unsigned long)i]; [self.cache setObject:obj forKey:key block:nil]; @@ -190,7 +190,7 @@ - (void)testOneThousandAndOneWrites } for (NSUInteger i = 0; i < max; i++) { - NSString *key = [[NSString alloc] initWithFormat:@"key %d", i]; + NSString *key = [[NSString alloc] initWithFormat:@"key %lu", (unsigned long)i]; [self.cache objectForKey:key block:^(TMCache *cache, NSString *key, id object) { dispatch_async(queue, ^{ From 3e2877755c468555681f41cef5dd6b2a9fd4625d Mon Sep 17 00:00:00 2001 From: Markus Kauppila Date: Sun, 23 Nov 2014 17:30:56 +0200 Subject: [PATCH 10/11] Fix formatting of macros --- TMCache/TMDiskCache.m | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/TMCache/TMDiskCache.m b/TMCache/TMDiskCache.m index 2e3afea..9ab4d4b 100644 --- a/TMCache/TMDiskCache.m +++ b/TMCache/TMDiskCache.m @@ -1,16 +1,19 @@ #import "TMDiskCache.h" -#define TMDiskCacheError(error) if (error) { NSLog(@"%@ (%d) ERROR: %@", \ - [[NSString stringWithUTF8String:__FILE__] lastPathComponent], \ - __LINE__, [error localizedDescription]); } +#define TMDiskCacheError(error) \ + if (error) { \ + NSLog(@"%@ (%d) ERROR: %@", \ + [[NSString stringWithUTF8String:__FILE__] lastPathComponent], \ + __LINE__, [error localizedDescription]); \ + } #define TMCacheStartBackgroundTask() \ - UIBackgroundTaskIdentifier taskID = UIBackgroundTaskInvalid; \ - taskID = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ \ - [[UIApplication sharedApplication] endBackgroundTask:taskID]; \ - }]; + UIBackgroundTaskIdentifier taskID = UIBackgroundTaskInvalid; \ + taskID = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ \ + [[UIApplication sharedApplication] endBackgroundTask:taskID]; \ + }]; #define TMCacheEndBackgroundTask() \ - [[UIApplication sharedApplication] endBackgroundTask:taskID]; + [[UIApplication sharedApplication] endBackgroundTask:taskID]; static NSString * const TMDiskCachePrefix = @"com.tumblr.TMDiskCache"; static NSString * const TMDiskCacheSharedName = @"TMDiskCacheShared"; From 2dd007d1aa61d6aef76487d668321fb8f50fcd12 Mon Sep 17 00:00:00 2001 From: Markus Kauppila Date: Sun, 23 Nov 2014 17:48:08 +0200 Subject: [PATCH 11/11] Switch from deprecated SenTestingKit to XCTest --- tests/TMCache.xcodeproj/project.pbxproj | 10 ++-- .../xcschemes/TMCacheTests.xcscheme | 4 +- tests/TMCacheTests/TMCacheTests.h | 4 +- tests/TMCacheTests/TMCacheTests.m | 48 +++++++++---------- 4 files changed, 31 insertions(+), 35 deletions(-) diff --git a/tests/TMCache.xcodeproj/project.pbxproj b/tests/TMCache.xcodeproj/project.pbxproj index 40afbba..c0caa94 100644 --- a/tests/TMCache.xcodeproj/project.pbxproj +++ b/tests/TMCache.xcodeproj/project.pbxproj @@ -13,7 +13,6 @@ D07F1EC2171AFB7A001DBA02 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = D07F1EC1171AFB7A001DBA02 /* main.m */; }; D07F1EC6171AFB7A001DBA02 /* TMAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = D07F1EC5171AFB7A001DBA02 /* TMAppDelegate.m */; }; D07F1ECC171AFB7A001DBA02 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = D07F1ECB171AFB7A001DBA02 /* Default-568h@2x.png */; }; - D07F1ED4171AFB7A001DBA02 /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D07F1ED3171AFB7A001DBA02 /* SenTestingKit.framework */; }; D07F1ED5171AFB7A001DBA02 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D07F1EB5171AFB7A001DBA02 /* UIKit.framework */; }; D07F1ED6171AFB7A001DBA02 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D07F1EB7171AFB7A001DBA02 /* Foundation.framework */; }; D07F1EE1171AFB7A001DBA02 /* TMCacheTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D07F1EE0171AFB7A001DBA02 /* TMCacheTests.m */; }; @@ -48,7 +47,6 @@ D07F1EC5171AFB7A001DBA02 /* TMAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TMAppDelegate.m; sourceTree = ""; }; D07F1ECB171AFB7A001DBA02 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = ""; }; D07F1ED2171AFB7A001DBA02 /* TMCacheTests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TMCacheTests.octest; sourceTree = BUILT_PRODUCTS_DIR; }; - D07F1ED3171AFB7A001DBA02 /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; }; D07F1EDB171AFB7A001DBA02 /* TMCacheTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "TMCacheTests-Info.plist"; sourceTree = ""; }; D07F1EDF171AFB7A001DBA02 /* TMCacheTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TMCacheTests.h; sourceTree = ""; }; D07F1EE0171AFB7A001DBA02 /* TMCacheTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TMCacheTests.m; sourceTree = ""; }; @@ -77,7 +75,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - D07F1ED4171AFB7A001DBA02 /* SenTestingKit.framework in Frameworks */, D07F1ED5171AFB7A001DBA02 /* UIKit.framework in Frameworks */, D07F1ED6171AFB7A001DBA02 /* Foundation.framework in Frameworks */, ); @@ -113,7 +110,6 @@ D07F1EB5171AFB7A001DBA02 /* UIKit.framework */, D07F1EB7171AFB7A001DBA02 /* Foundation.framework */, D07F1EB9171AFB7A001DBA02 /* CoreGraphics.framework */, - D07F1ED3171AFB7A001DBA02 /* SenTestingKit.framework */, ); name = Frameworks; sourceTree = ""; @@ -202,7 +198,7 @@ name = TMCacheTests; productName = TMCacheTests; productReference = D07F1ED2171AFB7A001DBA02 /* TMCacheTests.octest */; - productType = "com.apple.product-type.bundle.ocunit-test"; + productType = "com.apple.product-type.bundle.unit-test"; }; /* End PBXNativeTarget section */ @@ -396,6 +392,7 @@ FRAMEWORK_SEARCH_PATHS = ( "\"$(SDKROOT)/Developer/Library/Frameworks\"", "\"$(DEVELOPER_LIBRARY_DIR)/Frameworks\"", + "$(inherited)", ); GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "TMCache/TMCache-Prefix.pch"; @@ -403,7 +400,6 @@ PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUNDLE_LOADER)"; VALID_ARCHS = "arm64 armv7 armv7s i386 x86_64"; - WRAPPER_EXTENSION = octest; }; name = Debug; }; @@ -414,6 +410,7 @@ FRAMEWORK_SEARCH_PATHS = ( "\"$(SDKROOT)/Developer/Library/Frameworks\"", "\"$(DEVELOPER_LIBRARY_DIR)/Frameworks\"", + "$(inherited)", ); GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "TMCache/TMCache-Prefix.pch"; @@ -421,7 +418,6 @@ PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUNDLE_LOADER)"; VALID_ARCHS = "arm64 armv7 armv7s i386 x86_64"; - WRAPPER_EXTENSION = octest; }; name = Release; }; diff --git a/tests/TMCache.xcodeproj/xcshareddata/xcschemes/TMCacheTests.xcscheme b/tests/TMCache.xcodeproj/xcshareddata/xcschemes/TMCacheTests.xcscheme index 42c399e..a39cd2e 100644 --- a/tests/TMCache.xcodeproj/xcshareddata/xcschemes/TMCacheTests.xcscheme +++ b/tests/TMCache.xcodeproj/xcshareddata/xcschemes/TMCacheTests.xcscheme @@ -15,7 +15,7 @@ @@ -47,7 +47,7 @@ diff --git a/tests/TMCacheTests/TMCacheTests.h b/tests/TMCacheTests/TMCacheTests.h index 53f3f6d..694b197 100644 --- a/tests/TMCacheTests/TMCacheTests.h +++ b/tests/TMCacheTests/TMCacheTests.h @@ -1,5 +1,5 @@ -#import +#import -@interface TMCacheTests : SenTestCase +@interface TMCacheTests : XCTestCase @end diff --git a/tests/TMCacheTests/TMCacheTests.m b/tests/TMCacheTests/TMCacheTests.m index a234bca..065bb0a 100644 --- a/tests/TMCacheTests/TMCacheTests.m +++ b/tests/TMCacheTests/TMCacheTests.m @@ -18,7 +18,7 @@ - (void)setUp self.cache = [[TMCache alloc] initWithName:TMCacheTestName]; - STAssertNotNil(self.cache, @"test cache does not exist"); + XCTAssertNotNil(self.cache, @"test cache does not exist"); } - (void)tearDown @@ -27,7 +27,7 @@ - (void)tearDown self.cache = nil; - STAssertNil(self.cache, @"test cache did not deallocate"); + XCTAssertNil(self.cache, @"test cache did not deallocate"); [super tearDown]; } @@ -61,9 +61,9 @@ - (dispatch_time_t)timeout - (void)testCoreProperties { - STAssertTrue([self.cache.name isEqualToString:TMCacheTestName], @"wrong name"); - STAssertNotNil(self.cache.memoryCache, @"memory cache does not exist"); - STAssertNotNil(self.cache.diskCache, @"disk cache doe not exist"); + XCTAssertTrue([self.cache.name isEqualToString:TMCacheTestName], @"wrong name"); + XCTAssertNotNil(self.cache.memoryCache, @"memory cache does not exist"); + XCTAssertNotNil(self.cache.diskCache, @"disk cache doe not exist"); } - (void)testDiskCacheURL @@ -71,8 +71,8 @@ - (void)testDiskCacheURL BOOL isDir = NO; BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:[self.cache.diskCache.cacheURL path] isDirectory:&isDir]; - STAssertTrue(exists, @"disk cache directory does not exist"); - STAssertTrue(isDir, @"disk cache url is not a directory"); + XCTAssertTrue(exists, @"disk cache directory does not exist"); + XCTAssertTrue(isDir, @"disk cache url is not a directory"); } - (void)testObjectSet @@ -88,7 +88,7 @@ - (void)testObjectSet dispatch_semaphore_wait(semaphore, [self timeout]); - STAssertNotNil(image, @"object was not set"); + XCTAssertNotNil(image, @"object was not set"); } - (void)testObjectGet @@ -106,7 +106,7 @@ - (void)testObjectGet dispatch_semaphore_wait(semaphore, [self timeout]); - STAssertNotNil(image, @"object was not got"); + XCTAssertNotNil(image, @"object was not got"); } - (void)testObjectRemove @@ -124,7 +124,7 @@ - (void)testObjectRemove id object = [self.cache objectForKey:key]; - STAssertNil(object, @"object was not removed"); + XCTAssertNil(object, @"object was not removed"); } - (void)testMemoryCost @@ -135,16 +135,16 @@ - (void)testMemoryCost [self.cache.memoryCache setObject:key1 forKey:key1 withCost:1]; [self.cache.memoryCache setObject:key2 forKey:key2 withCost:2]; - STAssertTrue(self.cache.memoryCache.totalCost == 3, @"memory cache total cost was incorrect"); + XCTAssertTrue(self.cache.memoryCache.totalCost == 3, @"memory cache total cost was incorrect"); [self.cache.memoryCache trimToCost:1]; id object1 = [self.cache.memoryCache objectForKey:key1]; id object2 = [self.cache.memoryCache objectForKey:key2]; - STAssertNotNil(object1, @"object did not survive memory cache trim to cost"); - STAssertNil(object2, @"object was not trimmed despite exceeding cost"); - STAssertTrue(self.cache.memoryCache.totalCost == 1, @"cache had an unexpected total cost"); + XCTAssertNotNil(object1, @"object did not survive memory cache trim to cost"); + XCTAssertNil(object2, @"object was not trimmed despite exceeding cost"); + XCTAssertTrue(self.cache.memoryCache.totalCost == 1, @"cache had an unexpected total cost"); } - (void)testMemoryCostByDate @@ -160,16 +160,16 @@ - (void)testMemoryCostByDate id object1 = [self.cache.memoryCache objectForKey:key1]; id object2 = [self.cache.memoryCache objectForKey:key2]; - STAssertNil(object1, @"object was not trimmed despite exceeding cost"); - STAssertNil(object2, @"object was not trimmed despite exceeding cost"); - STAssertTrue(self.cache.memoryCache.totalCost == 0, @"cache had an unexpected total cost"); + XCTAssertNil(object1, @"object was not trimmed despite exceeding cost"); + XCTAssertNil(object2, @"object was not trimmed despite exceeding cost"); + XCTAssertTrue(self.cache.memoryCache.totalCost == 0, @"cache had an unexpected total cost"); } - (void)testDiskByteCount { [self.cache setObject:[self image] forKey:@"image"]; - STAssertTrue(self.cache.diskByteCount > 0, @"disk cache byte count was not greater than zero"); + XCTAssertTrue(self.cache.diskByteCount > 0, @"disk cache byte count was not greater than zero"); } - (void)testOneThousandAndOneWrites @@ -202,7 +202,7 @@ - (void)testOneThousandAndOneWrites dispatch_group_wait(group, [self timeout]); - STAssertTrue(count == 0, @"one or more object blocks failed to execute, possible queue deadlock"); + XCTAssertTrue(count == 0, @"one or more object blocks failed to execute, possible queue deadlock"); } - (void)testMemoryWarningBlock @@ -221,7 +221,7 @@ - (void)testMemoryWarningBlock dispatch_semaphore_wait(semaphore, [self timeout]); - STAssertTrue(blockDidExecute, @"memory warning block did not execute"); + XCTAssertTrue(blockDidExecute, @"memory warning block did not execute"); } - (void)testBackgroundBlock @@ -240,7 +240,7 @@ - (void)testBackgroundBlock dispatch_semaphore_wait(semaphore, [self timeout]); - STAssertTrue(blockDidExecute, @"app background block did not execute"); + XCTAssertTrue(blockDidExecute, @"app background block did not execute"); } - (void)testMemoryWarningProperty @@ -263,7 +263,7 @@ - (void)testMemoryWarningProperty dispatch_semaphore_wait(semaphore, [self timeout]); - STAssertNotNil(object, @"object was removed from the cache"); + XCTAssertNotNil(object, @"object was removed from the cache"); } - (void)testMemoryCacheEnumerationWithWarning @@ -295,7 +295,7 @@ - (void)testMemoryCacheEnumerationWithWarning dispatch_semaphore_wait(semaphore, [self timeout]); - STAssertTrue(objectCount == enumCount, @"some objects were not enumerated"); + XCTAssertTrue(objectCount == enumCount, @"some objects were not enumerated"); } - (void)testDiskCacheEnumeration @@ -323,7 +323,7 @@ - (void)testDiskCacheEnumeration dispatch_semaphore_wait(semaphore, [self timeout]); - STAssertTrue(objectCount == enumCount, @"some objects were not enumerated"); + XCTAssertTrue(objectCount == enumCount, @"some objects were not enumerated"); } @end