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/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/TMCache.m b/TMCache/TMCache.m index afba609..65fdaac 100644 --- a/TMCache/TMCache.m +++ b/TMCache/TMCache.m @@ -1,31 +1,20 @@ #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 () -#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]]; + return [self initWithName:name + rootPath:[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]]; } - (instancetype)initWithName:(NSString *)name rootPath:(NSString *)rootPath @@ -151,10 +140,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 +176,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 +209,6 @@ - (void)removeAllObjects:(TMCacheBlock)block if (strongSelf) block(strongSelf); }); - - #if !OS_OBJECT_USE_OBJC - dispatch_release(group); - #endif } } @@ -268,10 +245,6 @@ - (void)trimToDate:(NSDate *)date block:(TMCacheBlock)block if (strongSelf) block(strongSelf); }); - - #if !OS_OBJECT_USE_OBJC - dispatch_release(group); - #endif } } @@ -306,10 +279,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 +294,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 +308,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 +322,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 +333,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.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 = __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 - -NSString * const TMDiskCachePrefix = @"com.tumblr.TMDiskCache"; -NSString * const TMDiskCacheSharedName = @"TMDiskCacheShared"; +#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]; \ + }]; +#define TMCacheEndBackgroundTask() \ + [[UIApplication sharedApplication] endBackgroundTask:taskID]; + +static NSString * const TMDiskCachePrefix = @"com.tumblr.TMDiskCache"; +static NSString * const TMDiskCacheSharedName = @"TMDiskCacheShared"; @interface TMDiskCache () @property (assign) NSUInteger byteCount; @@ -40,7 +41,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 +266,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 +296,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 +318,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 +366,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 +481,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 } @@ -694,10 +696,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 +715,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 +730,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 +744,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 +755,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 +774,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 +785,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 +796,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 +810,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..33a771c 100644 --- a/TMCache/TMMemoryCache.m +++ b/TMCache/TMMemoryCache.m @@ -1,13 +1,9 @@ #import "TMMemoryCache.h" -NSString * const TMMemoryCachePrefix = @"com.tumblr.TMMemoryCache"; +static 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,14 +28,9 @@ @implementation TMMemoryCache - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; - - #if !OS_OBJECT_USE_OBJC - dispatch_release(_queue); - _queue = nil; - #endif } -- (id)init +- (instancetype)init { if (self = [super init]) { NSString *queueName = [[NSString alloc] initWithFormat:@"%@.%p", TMMemoryCachePrefix, self]; @@ -67,14 +58,12 @@ - (id)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; } @@ -95,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]; @@ -126,8 +113,6 @@ - (void)didObserveApocalypticNotification:(NSNotification *)notification strongSelf->_didEnterBackgroundBlock(strongSelf); }); } - - #endif } - (void)removeObjectAndExecuteBlocksForKey:(NSString *)key @@ -475,10 +460,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 +480,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 +494,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 +513,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 +524,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 +535,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 +546,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 +560,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 - diff --git a/tests/TMCache.xcodeproj/project.pbxproj b/tests/TMCache.xcodeproj/project.pbxproj index e340a5e..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"; + productType = "com.apple.product-type.bundle.unit-test"; }; /* End PBXNativeTarget section */ @@ -328,7 +324,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 +350,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 +366,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 +379,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; }; @@ -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 8122891..065bb0a 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"; +static const NSTimeInterval TMCacheTestBlockTimeout = 5.0; @interface TMCacheTests () @property (strong, nonatomic) TMCache *cache; @@ -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 @@ -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, ^{ @@ -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