Update travis script to use xcodebuild

This commit is contained in:
Garrett Moon
2016-03-05 17:28:51 -08:00
parent 231ccb1b21
commit 7c6a48f91f
39 changed files with 2370 additions and 2057 deletions

View File

@@ -690,7 +690,7 @@
completion:^(PINRemoteImageManagerResult *result)
{
image = result.image;
XCTAssert(image.size.width == 750, @"Large image should be downloaded");
XCTAssert(image.size.width == 750, @"Large image should be downloaded. result.image: %@, result.error: %@", result.image, result.error);
dispatch_semaphore_signal(semaphore);
}];
XCTAssert(dispatch_semaphore_wait(semaphore, [self timeout]) == 0, @"Semaphore timed out.");

View File

@@ -233,6 +233,7 @@
6003F587195388D20070C39A /* Frameworks */,
6003F588195388D20070C39A /* Resources */,
976369F3155C4085B1D6B257 /* Copy Pods Resources */,
CA06F4EBD160279B91AC4611 /* Embed Pods Frameworks */,
);
buildRules = (
);
@@ -252,6 +253,7 @@
68B5CDEA1A0BEC8C00A4BAAC /* Frameworks */,
68B5CDEB1A0BEC8C00A4BAAC /* Resources */,
82957B3C29244E2585DE33E5 /* Copy Pods Resources */,
01EE29DEABBCC2C48B66D4E8 /* Embed Pods Frameworks */,
);
buildRules = (
);
@@ -320,6 +322,21 @@
/* End PBXResourcesBuildPhase section */
/* Begin PBXShellScriptBuildPhase section */
01EE29DEABBCC2C48B66D4E8 /* Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Embed Pods Frameworks";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-PINRemoteImage Tests/Pods-PINRemoteImage Tests-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
03CA8BAB9131410DA4474CBA /* Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
@@ -380,6 +397,21 @@
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
CA06F4EBD160279B91AC4611 /* Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Embed Pods Frameworks";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-PINRemoteImage/Pods-PINRemoteImage-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
/* Begin PBXSourcesBuildPhase section */

View File

@@ -37,10 +37,10 @@
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
@@ -62,15 +62,18 @@
ReferencedContainer = "container:PINRemoteImage.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
@@ -86,10 +89,10 @@
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">

View File

@@ -23,12 +23,12 @@ PODS:
- libwebp/utils (0.5.0):
- libwebp/core
- libwebp/webp (0.5.0)
- PINCache (2.1.2)
- PINRemoteImage/Core (2.0):
- PINCache (2.2.2)
- PINRemoteImage/Core (2.0.1):
- PINCache (>= 2.1)
- PINRemoteImage/iOS (2.0):
- PINRemoteImage/iOS (2.0.1):
- PINRemoteImage/Core
- PINRemoteImage/WebP (2.0):
- PINRemoteImage/WebP (2.0.1):
- libwebp
- PINRemoteImage/Core
@@ -43,7 +43,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
libwebp: 68ba2001ba6806ee52837ebd77a551a0b6567e4e
PINCache: 9e70271f1bdd60c0465b7208adcc4b6acc1fc376
PINRemoteImage: 13b66fc3694c84eb1d38aebdee02c952e82fa7fe
PINCache: 078426d356ab95ef875e9e62e5c35a2ea3333c28
PINRemoteImage: b700a7bc774a19758092b5c06b3e076fe2cf3dce
COCOAPODS: 0.38.2
COCOAPODS: 0.39.0

View File

@@ -1,6 +1,6 @@
{
"name": "PINRemoteImage",
"version": "2.0",
"version": "2.0.1",
"summary": "A thread safe, performant, feature rich image fetcher",
"homepage": "https://github.com/pinterest/PINRemoteImage",
"license": "Apache 2.0",
@@ -9,7 +9,7 @@
},
"source": {
"git": "https://github.com/pinterest/PINRemoteImage.git",
"tag": "2.0"
"tag": "2.0.1"
},
"social_media_url": "https://twitter.com/garrettmoon",
"platforms": {

14
Example/Pods/Manifest.lock generated vendored
View File

@@ -23,12 +23,12 @@ PODS:
- libwebp/utils (0.5.0):
- libwebp/core
- libwebp/webp (0.5.0)
- PINCache (2.1.2)
- PINRemoteImage/Core (2.0):
- PINCache (2.2.2)
- PINRemoteImage/Core (2.0.1):
- PINCache (>= 2.1)
- PINRemoteImage/iOS (2.0):
- PINRemoteImage/iOS (2.0.1):
- PINRemoteImage/Core
- PINRemoteImage/WebP (2.0):
- PINRemoteImage/WebP (2.0.1):
- libwebp
- PINRemoteImage/Core
@@ -43,7 +43,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
libwebp: 68ba2001ba6806ee52837ebd77a551a0b6567e4e
PINCache: 9e70271f1bdd60c0465b7208adcc4b6acc1fc376
PINRemoteImage: 13b66fc3694c84eb1d38aebdee02c952e82fa7fe
PINCache: 078426d356ab95ef875e9e62e5c35a2ea3333c28
PINRemoteImage: b700a7bc774a19758092b5c06b3e076fe2cf3dce
COCOAPODS: 0.38.2
COCOAPODS: 0.39.0

View File

@@ -4,8 +4,8 @@
#import "PINCache.h"
NSString * const PINCachePrefix = @"com.pinterest.PINCache";
NSString * const PINCacheSharedName = @"PINCacheShared";
static NSString * const PINCachePrefix = @"com.pinterest.PINCache";
static NSString * const PINCacheSharedName = @"PINCacheShared";
@interface PINCache ()
#if OS_OBJECT_USE_OBJC
@@ -74,6 +74,8 @@ NSString * const PINCacheSharedName = @"PINCacheShared";
#pragma mark - Public Asynchronous Methods -
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wshadow"
- (void)objectForKey:(NSString *)key block:(PINCacheObjectBlock)block
{
@@ -89,13 +91,13 @@ NSString * const PINCacheSharedName = @"PINCacheShared";
__weak PINCache *weakSelf = strongSelf;
[strongSelf->_memoryCache objectForKey:key block:^(PINMemoryCache *cache, NSString *key, id object) {
[strongSelf->_memoryCache objectForKey:key block:^(PINMemoryCache *memoryCache, NSString *memoryCacheKey, id memoryCacheObject) {
PINCache *strongSelf = weakSelf;
if (!strongSelf)
return;
if (object) {
[strongSelf->_diskCache fileURLForKey:key block:^(PINDiskCache *cache, NSString *key, id <NSCoding> object, NSURL *fileURL) {
if (memoryCacheObject) {
[strongSelf->_diskCache fileURLForKey:memoryCacheKey block:^(PINDiskCache *diskCache, NSString *diskCacheKey, id <NSCoding> diskCacheObject, NSURL *fileURL) {
// update the access time on disk
}];
@@ -104,24 +106,24 @@ NSString * const PINCacheSharedName = @"PINCacheShared";
dispatch_async(strongSelf->_concurrentQueue, ^{
PINCache *strongSelf = weakSelf;
if (strongSelf)
block(strongSelf, key, object);
block(strongSelf, memoryCacheKey, memoryCacheObject);
});
} else {
__weak PINCache *weakSelf = strongSelf;
[strongSelf->_diskCache objectForKey:key block:^(PINDiskCache *cache, NSString *key, id <NSCoding> object, NSURL *fileURL) {
[strongSelf->_diskCache objectForKey:memoryCacheKey block:^(PINDiskCache *diskCache, NSString *diskCacheKey, id <NSCoding> diskCacheObject, NSURL *fileURL) {
PINCache *strongSelf = weakSelf;
if (!strongSelf)
return;
[strongSelf->_memoryCache setObject:object forKey:key block:nil];
[strongSelf->_memoryCache setObject:diskCacheObject forKey:diskCacheKey block:nil];
__weak PINCache *weakSelf = strongSelf;
dispatch_async(strongSelf->_concurrentQueue, ^{
PINCache *strongSelf = weakSelf;
if (strongSelf)
block(strongSelf, key, object);
block(strongSelf, diskCacheKey, diskCacheObject);
});
}];
}
@@ -129,6 +131,8 @@ NSString * const PINCacheSharedName = @"PINCacheShared";
});
}
#pragma clang diagnostic pop
- (void)setObject:(id <NSCoding>)object forKey:(NSString *)key block:(PINCacheObjectBlock)block
{
if (!key || !object)
@@ -143,11 +147,11 @@ NSString * const PINCacheSharedName = @"PINCacheShared";
dispatch_group_enter(group);
dispatch_group_enter(group);
memBlock = ^(PINMemoryCache *cache, NSString *key, id object) {
memBlock = ^(PINMemoryCache *memoryCache, NSString *memoryCacheKey, id memoryCacheObject) {
dispatch_group_leave(group);
};
diskBlock = ^(PINDiskCache *cache, NSString *key, id <NSCoding> object, NSURL *fileURL) {
diskBlock = ^(PINDiskCache *diskCache, NSString *diskCacheKey, id <NSCoding> memoryCacheObject, NSURL *memoryCacheFileURL) {
dispatch_group_leave(group);
};
}
@@ -183,11 +187,11 @@ NSString * const PINCacheSharedName = @"PINCacheShared";
dispatch_group_enter(group);
dispatch_group_enter(group);
memBlock = ^(PINMemoryCache *cache, NSString *key, id object) {
memBlock = ^(PINMemoryCache *memoryCache, NSString *memoryCacheKey, id memoryCacheObject) {
dispatch_group_leave(group);
};
diskBlock = ^(PINDiskCache *cache, NSString *key, id <NSCoding> object, NSURL *fileURL) {
diskBlock = ^(PINDiskCache *diskCache, NSString *diskCacheKey, id <NSCoding> memoryCacheObject, NSURL *memoryCacheFileURL) {
dispatch_group_leave(group);
};
}

View File

@@ -97,6 +97,16 @@ typedef void (^PINDiskCacheObjectBlock)(PINDiskCache *cache, NSString *key, id <
*/
@property (assign) NSTimeInterval ageLimit;
/**
If ttlCache is YES, the cache behaves like a ttlCache. This means that once an object enters the
cache, it only lives as long as self.ageLimit. This has the following implications:
- Accessing an object in the cache does not extend that object's lifetime in the cache
- When attempting to access an object in the cache that has lived longer than self.ageLimit,
the cache will behave as if the object does not exist
*/
@property (nonatomic, assign, getter=isTTLCache) BOOL ttlCache;
#pragma mark -
/// @name Event Blocks

View File

@@ -12,11 +12,11 @@
[[NSString stringWithUTF8String:__FILE__] lastPathComponent], \
__LINE__, [error localizedDescription]); }
NSString * const PINDiskCachePrefix = @"com.pinterest.PINDiskCache";
NSString * const PINDiskCacheSharedName = @"PINDiskCacheShared";
static NSString * const PINDiskCachePrefix = @"com.pinterest.PINDiskCache";
static NSString * const PINDiskCacheSharedName = @"PINDiskCacheShared";
@interface PINBackgroundTask : NSObject
#if !defined(PIN_APP_EXTENSIONS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0 && !TARGET_OS_WATCH
@property (atomic, assign) UIBackgroundTaskIdentifier taskID;
#endif
+ (instancetype)start;
@@ -48,6 +48,7 @@ NSString * const PINDiskCacheSharedName = @"PINDiskCacheShared";
@synthesize didRemoveAllObjectsBlock = _didRemoveAllObjectsBlock;
@synthesize byteLimit = _byteLimit;
@synthesize ageLimit = _ageLimit;
@synthesize ttlCache = _ttlCache;
#pragma mark - Initialization -
@@ -97,8 +98,15 @@ NSString * const PINDiskCacheSharedName = @"PINDiskCacheShared";
NSString *pathComponent = [[NSString alloc] initWithFormat:@"%@.%@", PINDiskCachePrefix, _name];
_cacheURL = [NSURL fileURLWithPathComponents:@[ rootPath, pathComponent ]];
[self createCacheDirectory];
[self initializeDiskProperties];
//we don't want to do anything without setting up the disk cache, but we also don't want to block init, it can take a while to initialize
//this is only safe because we use a dispatch_semaphore as a lock. If we switch to an NSLock or posix locks, this will *no longer be safe*.
[self lock];
dispatch_async(_asyncQueue, ^{
[self createCacheDirectory];
[self initializeDiskProperties];
[self unlock];
});
}
return self;
}
@@ -141,16 +149,46 @@ NSString * const PINDiskCacheSharedName = @"PINDiskCacheShared";
- (NSString *)encodedString:(NSString *)string
{
if (![string length])
if (![string length]) {
return @"";
return [string stringByAddingPercentEncodingWithAllowedCharacters:[[NSCharacterSet characterSetWithCharactersInString:@".:/"] invertedSet]];
}
if ([string respondsToSelector:@selector(stringByAddingPercentEncodingWithAllowedCharacters:)]) {
return [string stringByAddingPercentEncodingWithAllowedCharacters:[[NSCharacterSet characterSetWithCharactersInString:@".:/%"] invertedSet]];
}
else {
CFStringRef static const charsToEscape = CFSTR(".:/%");
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
CFStringRef escapedString = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
(__bridge CFStringRef)string,
NULL,
charsToEscape,
kCFStringEncodingUTF8);
#pragma clang diagnostic pop
return (__bridge_transfer NSString *)escapedString;
}
}
- (NSString *)decodedString:(NSString *)string
{
if (![string length])
if (![string length]) {
return @"";
return [string stringByRemovingPercentEncoding];
}
if ([string respondsToSelector:@selector(stringByRemovingPercentEncoding)]) {
return [string stringByRemovingPercentEncoding];
}
else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
CFStringRef unescapedString = CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault,
(__bridge CFStringRef)string,
CFSTR(""),
kCFStringEncodingUTF8);
#pragma clang diagnostic pop
return (__bridge_transfer NSString *)unescapedString;
}
}
#pragma mark - Private Trash Methods -
@@ -208,17 +246,17 @@ NSString * const PINDiskCacheSharedName = @"PINDiskCacheShared";
PINBackgroundTask *task = [PINBackgroundTask start];
dispatch_async([self sharedTrashQueue], ^{
NSError *error = nil;
NSError *searchTrashedItemsError = nil;
NSArray *trashedItems = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:[self sharedTrashURL]
includingPropertiesForKeys:nil
options:0
error:&error];
PINDiskCacheError(error);
error:&searchTrashedItemsError];
PINDiskCacheError(searchTrashedItemsError);
for (NSURL *trashedItemURL in trashedItems) {
NSError *error = nil;
[[NSFileManager defaultManager] removeItemAtURL:trashedItemURL error:&error];
PINDiskCacheError(error);
NSError *removeTrashedItemError = nil;
[[NSFileManager defaultManager] removeItemAtURL:trashedItemURL error:&removeTrashedItemError];
PINDiskCacheError(removeTrashedItemError);
}
[task end];
@@ -588,7 +626,9 @@ NSString * const PINDiskCacheSharedName = @"PINDiskCacheShared";
fileURL = [self encodedFileURLForKey:key];
object = nil;
if ([[NSFileManager defaultManager] fileExistsAtPath:[fileURL path]]) {
if ([[NSFileManager defaultManager] fileExistsAtPath:[fileURL path]] &&
// If the cache should behave like a TTL cache, then only fetch the object if there's a valid ageLimit and the object is still alive
(!self->_ttlCache || self->_ageLimit <= 0 || fabs([[_dates objectForKey:key] timeIntervalSinceDate:now]) < self->_ageLimit)) {
@try {
object = [NSKeyedUnarchiver unarchiveObjectWithFile:[fileURL path]];
}
@@ -597,8 +637,9 @@ NSString * const PINDiskCacheSharedName = @"PINDiskCacheShared";
[[NSFileManager defaultManager] removeItemAtPath:[fileURL path] error:&error];
PINDiskCacheError(error);
}
if (!self->_ttlCache) {
[self setFileModificationDate:now forURL:fileURL];
}
}
[self unlock];
@@ -622,7 +663,10 @@ NSString * const PINDiskCacheSharedName = @"PINDiskCacheShared";
fileURL = [self encodedFileURLForKey:key];
if ([[NSFileManager defaultManager] fileExistsAtPath:[fileURL path]]) {
[self setFileModificationDate:now forURL:fileURL];
// Don't update the file modification time, if self is a ttlCache
if (!self->_ttlCache) {
[self setFileModificationDate:now forURL:fileURL];
}
} else {
fileURL = nil;
}
@@ -797,11 +841,15 @@ NSString * const PINDiskCacheSharedName = @"PINDiskCacheShared";
PINBackgroundTask *task = [PINBackgroundTask start];
[self lock];
NSDate *now = [NSDate date];
NSArray *keysSortedByDate = [self->_dates keysSortedByValueUsingSelector:@selector(compare:)];
for (NSString *key in keysSortedByDate) {
NSURL *fileURL = [self encodedFileURLForKey:key];
block(self, key, nil, fileURL);
// If the cache should behave like a TTL cache, then only fetch the object if there's a valid ageLimit and the object is still alive
if (!self->_ttlCache || self->_ageLimit <= 0 || fabs([[_dates objectForKey:key] timeIntervalSinceDate:now]) < self->_ageLimit) {
block(self, key, nil, fileURL);
}
}
[self unlock];
@@ -1022,6 +1070,30 @@ NSString * const PINDiskCacheSharedName = @"PINDiskCacheShared";
});
}
- (BOOL)isTTLCache {
BOOL isTTLCache;
[self lock];
isTTLCache = _ttlCache;
[self unlock];
return isTTLCache;
}
- (void)setTtlCache:(BOOL)ttlCache {
__weak PINDiskCache *weakSelf = self;
dispatch_async(_asyncQueue, ^{
PINDiskCache *strongSelf = weakSelf;
if (!strongSelf)
return;
[strongSelf lock];
strongSelf->_ttlCache = ttlCache;
[strongSelf unlock];
});
}
- (void)lock
{
dispatch_semaphore_wait(_lockSemaphore, DISPATCH_TIME_FOREVER);
@@ -1035,10 +1107,24 @@ NSString * const PINDiskCacheSharedName = @"PINDiskCacheShared";
@end
@implementation PINBackgroundTask
+ (BOOL)isAppExtension {
static BOOL isExtension;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSDictionary *extensionDictionary = [[NSBundle mainBundle] infoDictionary][@"NSExtension"];
isExtension = [extensionDictionary isKindOfClass:[NSDictionary class]];
});
return isExtension;
}
- (instancetype)init
{
if (self = [super init]) {
#if !defined(PIN_APP_EXTENSIONS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0 && !TARGET_OS_WATCH
_taskID = UIBackgroundTaskInvalid;
#endif
}
@@ -1047,23 +1133,38 @@ NSString * const PINDiskCacheSharedName = @"PINDiskCacheShared";
+ (instancetype)start
{
PINBackgroundTask *task = [[self alloc] init];
#if !defined(PIN_APP_EXTENSIONS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0
task.taskID = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
PINBackgroundTask *task = nil;
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0 && !TARGET_OS_WATCH
if ([self.class isAppExtension]) {
return task;
}
task = [[self alloc] init];
UIApplication *sharedApplication = [UIApplication performSelector:@selector(sharedApplication)];
task.taskID = [sharedApplication beginBackgroundTaskWithExpirationHandler:^{
UIBackgroundTaskIdentifier taskID = task.taskID;
task.taskID = UIBackgroundTaskInvalid;
[[UIApplication sharedApplication] endBackgroundTask:taskID];
[sharedApplication endBackgroundTask:taskID];
}];
#endif
return task;
}
- (void)end
{
#if !defined(PIN_APP_EXTENSIONS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0 && !TARGET_OS_WATCH
if ([self.class isAppExtension]) {
return;
}
UIBackgroundTaskIdentifier taskID = self.taskID;
self.taskID = UIBackgroundTaskInvalid;
[[UIApplication sharedApplication] endBackgroundTask:taskID];
UIApplication *sharedApplication = [UIApplication performSelector:@selector(sharedApplication)];
[sharedApplication endBackgroundTask:taskID];
#endif
}

View File

@@ -65,6 +65,16 @@ typedef void (^PINMemoryCacheObjectBlock)(PINMemoryCache *cache, NSString *key,
*/
@property (assign) NSTimeInterval ageLimit;
/**
If ttlCache is YES, the cache behaves like a ttlCache. This means that once an object enters the
cache, it only lives as long as self.ageLimit. This has the following implications:
- Accessing an object in the cache does not extend that object's lifetime in the cache
- When attempting to access an object in the cache that has lived longer than self.ageLimit,
the cache will behave as if the object does not exist
*/
@property (nonatomic, assign, getter=isTTLCache) BOOL ttlCache;
/**
When `YES` on iOS the cache will remove all objects when the app receives a memory warning.
Defaults to `YES`.

View File

@@ -8,7 +8,7 @@
#import <UIKit/UIKit.h>
#endif
NSString * const PINMemoryCachePrefix = @"com.pinterest.PINMemoryCache";
static NSString * const PINMemoryCachePrefix = @"com.pinterest.PINMemoryCache";
@interface PINMemoryCache ()
#if OS_OBJECT_USE_OBJC
@@ -28,6 +28,7 @@ NSString * const PINMemoryCachePrefix = @"com.pinterest.PINMemoryCache";
@synthesize ageLimit = _ageLimit;
@synthesize costLimit = _costLimit;
@synthesize totalCost = _totalCost;
@synthesize ttlCache = _ttlCache;
@synthesize willAddObjectBlock = _willAddObjectBlock;
@synthesize willRemoveObjectBlock = _willRemoveObjectBlock;
@synthesize willRemoveAllObjectsBlock = _willRemoveAllObjectsBlock;
@@ -79,18 +80,17 @@ NSString * const PINMemoryCachePrefix = @"com.pinterest.PINMemoryCache";
_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
#if !defined(PIN_APP_EXTENSIONS)
object:[UIApplication sharedApplication]];
#else
object:nil];
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0 && !TARGET_OS_WATCH
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didReceiveEnterBackgroundNotification:)
name:UIApplicationDidEnterBackgroundNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didReceiveMemoryWarningNotification:)
name:UIApplicationDidReceiveMemoryWarningNotification
object:nil];
#endif
}
#endif
}
return self;
}
@@ -109,51 +109,47 @@ NSString * const PINMemoryCachePrefix = @"com.pinterest.PINMemoryCache";
#pragma mark - Private Methods -
- (void)didObserveApocalypticNotification:(NSNotification *)notification
- (void)didReceiveMemoryWarningNotification:(NSNotification *)notification {
if (self.removeAllObjectsOnMemoryWarning)
[self removeAllObjects:nil];
__weak PINMemoryCache *weakSelf = self;
dispatch_async(_concurrentQueue, ^{
PINMemoryCache *strongSelf = weakSelf;
if (!strongSelf) {
return;
}
[strongSelf lock];
PINMemoryCacheBlock didReceiveMemoryWarningBlock = strongSelf->_didReceiveMemoryWarningBlock;
[strongSelf unlock];
if (didReceiveMemoryWarningBlock)
didReceiveMemoryWarningBlock(strongSelf);
});
}
- (void)didReceiveEnterBackgroundNotification:(NSNotification *)notification
{
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0
if (self.removeAllObjectsOnEnteringBackground)
[self removeAllObjects:nil];
if ([[notification name] isEqualToString:UIApplicationDidReceiveMemoryWarningNotification]) {
if (self.removeAllObjectsOnMemoryWarning)
[self removeAllObjects:nil];
__weak PINMemoryCache *weakSelf = self;
__weak PINMemoryCache *weakSelf = self;
dispatch_async(_concurrentQueue, ^{
PINMemoryCache *strongSelf = weakSelf;
if (!strongSelf) {
return;
}
dispatch_async(_concurrentQueue, ^{
PINMemoryCache *strongSelf = weakSelf;
if (!strongSelf) {
return;
}
[strongSelf lock];
PINMemoryCacheBlock didReceiveMemoryWarningBlock = strongSelf->_didReceiveMemoryWarningBlock;
[strongSelf unlock];
if (didReceiveMemoryWarningBlock)
didReceiveMemoryWarningBlock(strongSelf);
});
} else if ([[notification name] isEqualToString:UIApplicationDidEnterBackgroundNotification]) {
if (self.removeAllObjectsOnEnteringBackground)
[self removeAllObjects:nil];
[strongSelf lock];
PINMemoryCacheBlock didEnterBackgroundBlock = strongSelf->_didEnterBackgroundBlock;
[strongSelf unlock];
__weak PINMemoryCache *weakSelf = self;
dispatch_async(_concurrentQueue, ^{
PINMemoryCache *strongSelf = weakSelf;
if (!strongSelf) {
return;
}
[strongSelf lock];
PINMemoryCacheBlock didEnterBackgroundBlock = strongSelf->_didEnterBackgroundBlock;
[strongSelf unlock];
if (didEnterBackgroundBlock)
didEnterBackgroundBlock(strongSelf);
});
}
#endif
if (didEnterBackgroundBlock)
didEnterBackgroundBlock(strongSelf);
});
}
- (void)removeObjectAndExecuteBlocksForKey:(NSString *)key
@@ -203,8 +199,10 @@ NSString * const PINMemoryCachePrefix = @"com.pinterest.PINMemoryCache";
- (void)trimToCostLimit:(NSUInteger)limit
{
NSUInteger totalCost = 0;
[self lock];
NSUInteger totalCost = _totalCost;
totalCost = _totalCost;
NSArray *keysSortedByCost = [_costs keysSortedByValueUsingSelector:@selector(compare:)];
[self unlock];
@@ -216,7 +214,7 @@ NSString * const PINMemoryCachePrefix = @"com.pinterest.PINMemoryCache";
[self removeObjectAndExecuteBlocksForKey:key];
[self lock];
NSUInteger totalCost = _totalCost;
totalCost = _totalCost;
[self unlock];
if (totalCost <= limit)
@@ -226,8 +224,10 @@ NSString * const PINMemoryCachePrefix = @"com.pinterest.PINMemoryCache";
- (void)trimToCostLimitByDate:(NSUInteger)limit
{
NSUInteger totalCost = 0;
[self lock];
NSUInteger totalCost = _totalCost;
totalCost = _totalCost;
NSArray *keysSortedByDate = [_dates keysSortedByValueUsingSelector:@selector(compare:)];
[self unlock];
@@ -238,7 +238,7 @@ NSString * const PINMemoryCachePrefix = @"com.pinterest.PINMemoryCache";
[self removeObjectAndExecuteBlocksForKey:key];
[self lock];
NSUInteger totalCost = _totalCost;
totalCost = _totalCost;
[self unlock];
if (totalCost <= limit)
break;
@@ -383,13 +383,16 @@ NSString * const PINMemoryCachePrefix = @"com.pinterest.PINMemoryCache";
- (__nullable id)objectForKey:(NSString *)key
{
NSDate *now = [[NSDate alloc] init];
if (!key)
return nil;
NSDate *now = [[NSDate alloc] init];
[self lock];
id object = _dictionary[key];
id object = nil;
// If the cache should behave like a TTL cache, then only fetch the object if there's a valid ageLimit and the object is still alive
if (!self->_ttlCache || self->_ageLimit <= 0 || fabs([[_dates objectForKey:key] timeIntervalSinceDate:now]) < self->_ageLimit) {
object = _dictionary[key];
}
[self unlock];
if (object) {
@@ -408,8 +411,6 @@ NSString * const PINMemoryCachePrefix = @"com.pinterest.PINMemoryCache";
- (void)setObject:(id)object forKey:(NSString *)key withCost:(NSUInteger)cost
{
NSDate *now = [[NSDate alloc] init];
if (!key || !object)
return;
@@ -424,7 +425,7 @@ NSString * const PINMemoryCachePrefix = @"com.pinterest.PINMemoryCache";
[self lock];
_dictionary[key] = object;
_dates[key] = now;
_dates[key] = [[NSDate alloc] init];
_costs[key] = @(cost);
_totalCost += cost;
@@ -497,10 +498,14 @@ NSString * const PINMemoryCachePrefix = @"com.pinterest.PINMemoryCache";
return;
[self lock];
NSDate *now = [[NSDate alloc] init];
NSArray *keysSortedByDate = [_dates keysSortedByValueUsingSelector:@selector(compare:)];
for (NSString *key in keysSortedByDate) {
block(self, key, _dictionary[key]);
// If the cache should behave like a TTL cache, then only fetch the object if there's a valid ageLimit and the object is still alive
if (!self->_ttlCache || self->_ageLimit <= 0 || fabs([[_dates objectForKey:key] timeIntervalSinceDate:now]) < self->_ageLimit) {
block(self, key, _dictionary[key]);
}
}
[self unlock];
}
@@ -681,6 +686,23 @@ NSString * const PINMemoryCachePrefix = @"com.pinterest.PINMemoryCache";
return cost;
}
- (BOOL)isTTLCache {
BOOL isTTLCache;
[self lock];
isTTLCache = _ttlCache;
[self unlock];
return isTTLCache;
}
- (void)setTtlCache:(BOOL)ttlCache {
[self lock];
_ttlCache = ttlCache;
[self unlock];
}
- (void)lock
{
dispatch_semaphore_wait(_lockSemaphore, DISPATCH_TIME_FOREVER);

View File

@@ -13,7 +13,7 @@
UIImage *img = [[UIImage alloc] initWithData:data scale:[[UIScreen mainScreen] scale]];
[[PINCache sharedCache] setObject:img forKey:@"image" block:nil]; // returns immediately
```
Get them back out like this:
```objective-c
@@ -23,7 +23,7 @@ Get them back out like this:
NSLog(@"image scale: %f", image.scale);
}];
```
Both `PINMemoryCache` and PINDiskCache use locks to protect reads and writes. `PINCache` coordinates them so that objects added to memory are available immediately to other threads while being written to disk safely in the background. Both caches are public properties of `PINCache`, so it's easy to manipulate one or the other separately if necessary.
Collections work too. Thanks to the magic of `NSKeyedArchiver`, objects repeated in a collection only occupy the space of one on disk:

File diff suppressed because it is too large Load Diff

View File

@@ -1,60 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0700"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForAnalyzing = "YES"
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES">
<BuildableReference
BuildableIdentifier = 'primary'
BlueprintIdentifier = 'B94A52992B26EA4A87AFEDE8'
BlueprintName = 'PINRemoteImage'
ReferencedContainer = 'container:Pods.xcodeproj'
BuildableName = 'libPINRemoteImage.a'>
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
buildConfiguration = "Debug"
allowLocationSimulation = "YES">
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES"
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@@ -14,7 +14,7 @@
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "4689FA171B6841C3229576DB"
BlueprintIdentifier = "4659B8FEB8162320413F74963CC40CBE"
BuildableName = "libPods-PINRemoteImage Tests-PINRemoteImage.a"
BlueprintName = "Pods-PINRemoteImage Tests-PINRemoteImage"
ReferencedContainer = "container:Pods.xcodeproj">
@@ -23,33 +23,42 @@
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
<AdditionalOptions>
</AdditionalOptions>
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "4659B8FEB8162320413F74963CC40CBE"
BuildableName = "libPods-PINRemoteImage Tests-PINRemoteImage.a"
BlueprintName = "Pods-PINRemoteImage Tests-PINRemoteImage"
ReferencedContainer = "container:Pods.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction

View File

@@ -7,17 +7,17 @@
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForAnalyzing = "YES"
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
buildForArchiving = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A1FC30CBF2490C222FEB872B"
BuildableName = "libPods-PINRemoteImage-PINRemoteImage.a"
BlueprintName = "Pods-PINRemoteImage-PINRemoteImage"
ReferencedContainer = "container:Pods.xcodeproj">
BuildableIdentifier = 'primary'
BlueprintIdentifier = '385E12D68B3AF6655007C776'
BlueprintName = 'Pods-PINRemoteImage-PINRemoteImage'
ReferencedContainer = 'container:Pods.xcodeproj'
BuildableName = 'libPods-PINRemoteImage-PINRemoteImage.a'>
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
@@ -29,28 +29,26 @@
buildConfiguration = "Debug">
<AdditionalOptions>
</AdditionalOptions>
<Testables>
</Testables>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
buildConfiguration = "Debug"
allowLocationSimulation = "YES">
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
shouldUseLaunchSchemeArgsEnv = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">

View File

@@ -1,6 +0,0 @@
#include "Pods-PINRemoteImage Tests-PINCache.xcconfig"
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/PINCache" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/PINCache" "${PODS_ROOT}/Headers/Public/PINRemoteImage" "${PODS_ROOT}/Headers/Public/libwebp" "${PODS_ROOT}/Headers/Public/libwebp/webp"
OTHER_LDFLAGS = ${PODS_PINREMOTEIMAGE_TESTS_PINCACHE_OTHER_LDFLAGS}
PODS_ROOT = ${SRCROOT}
SKIP_INSTALL = YES

View File

@@ -2,3 +2,6 @@
#import <UIKit/UIKit.h>
#endif
#ifndef TARGET_OS_WATCH
#define TARGET_OS_WATCH 0
#endif

View File

@@ -1 +1,5 @@
PODS_PINREMOTEIMAGE_TESTS_PINCACHE_OTHER_LDFLAGS = -framework "Foundation" -weak_framework "UIKit"
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/PINCache" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/PINCache" "${PODS_ROOT}/Headers/Public/PINRemoteImage" "${PODS_ROOT}/Headers/Public/libwebp"
OTHER_LDFLAGS = -framework "Foundation" -weak_framework "UIKit"
PODS_ROOT = ${SRCROOT}
SKIP_INSTALL = YES

View File

@@ -1,6 +0,0 @@
#include "Pods-PINRemoteImage Tests-PINRemoteImage.xcconfig"
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 ${PODS_PINREMOTEIMAGE_TESTS_PINREMOTEIMAGE_GCC_PREPROCESSOR_DEFINITIONS}
HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/PINRemoteImage" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/PINCache" "${PODS_ROOT}/Headers/Public/PINRemoteImage" "${PODS_ROOT}/Headers/Public/libwebp" "${PODS_ROOT}/Headers/Public/libwebp/webp"
OTHER_LDFLAGS = ${PODS_PINREMOTEIMAGE_TESTS_PINREMOTEIMAGE_OTHER_LDFLAGS}
PODS_ROOT = ${SRCROOT}
SKIP_INSTALL = YES

View File

@@ -1,2 +1,5 @@
PODS_PINREMOTEIMAGE_TESTS_PINREMOTEIMAGE_GCC_PREPROCESSOR_DEFINITIONS = $(inherited) PIN_WEBP=1
PODS_PINREMOTEIMAGE_TESTS_PINREMOTEIMAGE_OTHER_LDFLAGS = -framework "Accelerate" -framework "ImageIO"
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 $(inherited) PIN_WEBP=1
HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/PINRemoteImage" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/PINCache" "${PODS_ROOT}/Headers/Public/PINRemoteImage" "${PODS_ROOT}/Headers/Public/libwebp"
OTHER_LDFLAGS = -framework "Accelerate" -framework "ImageIO"
PODS_ROOT = ${SRCROOT}
SKIP_INSTALL = YES

View File

@@ -1,5 +0,0 @@
#include "Pods-PINRemoteImage Tests-libwebp.xcconfig"
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/libwebp" "${PODS_ROOT}/Headers/Private/libwebp/webp" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/PINCache" "${PODS_ROOT}/Headers/Public/PINRemoteImage" "${PODS_ROOT}/Headers/Public/libwebp" "${PODS_ROOT}/Headers/Public/libwebp/webp"
PODS_ROOT = ${SRCROOT}
SKIP_INSTALL = YES

View File

@@ -0,0 +1,4 @@
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/libwebp" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/PINCache" "${PODS_ROOT}/Headers/Public/PINRemoteImage" "${PODS_ROOT}/Headers/Public/libwebp"
PODS_ROOT = ${SRCROOT}
SKIP_INSTALL = YES

View File

@@ -0,0 +1,84 @@
#!/bin/sh
set -e
echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
SWIFT_STDLIB_PATH="${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}"
install_framework()
{
if [ -r "${BUILT_PRODUCTS_DIR}/$1" ]; then
local source="${BUILT_PRODUCTS_DIR}/$1"
elif [ -r "${BUILT_PRODUCTS_DIR}/$(basename "$1")" ]; then
local source="${BUILT_PRODUCTS_DIR}/$(basename "$1")"
elif [ -r "$1" ]; then
local source="$1"
fi
local destination="${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
if [ -L "${source}" ]; then
echo "Symlinked..."
source="$(readlink "${source}")"
fi
# use filter instead of exclude so missing patterns dont' throw errors
echo "rsync -av --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${destination}\""
rsync -av --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${destination}"
local basename
basename="$(basename -s .framework "$1")"
binary="${destination}/${basename}.framework/${basename}"
if ! [ -r "$binary" ]; then
binary="${destination}/${basename}"
fi
# Strip invalid architectures so "fat" simulator / device frameworks work on device
if [[ "$(file "$binary")" == *"dynamically linked shared library"* ]]; then
strip_invalid_archs "$binary"
fi
# Resign the code if required by the build settings to avoid unstable apps
code_sign_if_enabled "${destination}/$(basename "$1")"
# Embed linked Swift runtime libraries. No longer necessary as of Xcode 7.
if [ "${XCODE_VERSION_MAJOR}" -lt 7 ]; then
local swift_runtime_libs
swift_runtime_libs=$(xcrun otool -LX "$binary" | grep --color=never @rpath/libswift | sed -E s/@rpath\\/\(.+dylib\).*/\\1/g | uniq -u && exit ${PIPESTATUS[0]})
for lib in $swift_runtime_libs; do
echo "rsync -auv \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\""
rsync -auv "${SWIFT_STDLIB_PATH}/${lib}" "${destination}"
code_sign_if_enabled "${destination}/${lib}"
done
fi
}
# Signs a framework with the provided identity
code_sign_if_enabled() {
if [ -n "${EXPANDED_CODE_SIGN_IDENTITY}" -a "${CODE_SIGNING_REQUIRED}" != "NO" -a "${CODE_SIGNING_ALLOWED}" != "NO" ]; then
# Use the current code_sign_identitiy
echo "Code Signing $1 with Identity ${EXPANDED_CODE_SIGN_IDENTITY_NAME}"
echo "/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} --preserve-metadata=identifier,entitlements \"$1\""
/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} --preserve-metadata=identifier,entitlements "$1"
fi
}
# Strip invalid architectures
strip_invalid_archs() {
binary="$1"
# Get architectures for current file
archs="$(lipo -info "$binary" | rev | cut -d ':' -f1 | rev)"
stripped=""
for arch in $archs; do
if ! [[ "${VALID_ARCHS}" == *"$arch"* ]]; then
# Strip non-valid architectures in-place
lipo -remove "$arch" -output "$binary" "$binary" || exit 1
stripped="$stripped $arch"
fi
done
if [[ "$stripped" ]]; then
echo "Stripped $binary of architectures:$stripped"
fi
}

View File

@@ -60,7 +60,7 @@ install_resource()
mkdir -p "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
if [[ "${ACTION}" == "install" ]]; then
if [[ "${ACTION}" == "install" ]] && [[ "${SKIP_INSTALL}" == "NO" ]]; then
mkdir -p "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
fi

View File

@@ -1,5 +1,5 @@
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 $(inherited) PIN_WEBP=1 $(inherited) PIN_WEBP=1
HEADER_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/PINCache" "${PODS_ROOT}/Headers/Public/PINRemoteImage" "${PODS_ROOT}/Headers/Public/libwebp" "${PODS_ROOT}/Headers/Public/libwebp/webp"
OTHER_CFLAGS = $(inherited) -isystem "${PODS_ROOT}/Headers/Public" -isystem "${PODS_ROOT}/Headers/Public/PINCache" -isystem "${PODS_ROOT}/Headers/Public/PINRemoteImage" -isystem "${PODS_ROOT}/Headers/Public/libwebp" -isystem "${PODS_ROOT}/Headers/Public/libwebp/webp"
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 $(inherited) PIN_WEBP=1
HEADER_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/PINCache" "${PODS_ROOT}/Headers/Public/PINRemoteImage" "${PODS_ROOT}/Headers/Public/libwebp"
OTHER_CFLAGS = $(inherited) -isystem "${PODS_ROOT}/Headers/Public" -isystem "${PODS_ROOT}/Headers/Public/PINCache" -isystem "${PODS_ROOT}/Headers/Public/PINRemoteImage" -isystem "${PODS_ROOT}/Headers/Public/libwebp"
OTHER_LDFLAGS = $(inherited) -ObjC -l"Pods-PINRemoteImage Tests-PINCache" -l"Pods-PINRemoteImage Tests-PINRemoteImage" -l"Pods-PINRemoteImage Tests-libwebp" -framework "Accelerate" -framework "Foundation" -framework "ImageIO" -weak_framework "UIKit"
PODS_ROOT = ${SRCROOT}/Pods

View File

@@ -1,5 +1,5 @@
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 $(inherited) PIN_WEBP=1 $(inherited) PIN_WEBP=1
HEADER_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/PINCache" "${PODS_ROOT}/Headers/Public/PINRemoteImage" "${PODS_ROOT}/Headers/Public/libwebp" "${PODS_ROOT}/Headers/Public/libwebp/webp"
OTHER_CFLAGS = $(inherited) -isystem "${PODS_ROOT}/Headers/Public" -isystem "${PODS_ROOT}/Headers/Public/PINCache" -isystem "${PODS_ROOT}/Headers/Public/PINRemoteImage" -isystem "${PODS_ROOT}/Headers/Public/libwebp" -isystem "${PODS_ROOT}/Headers/Public/libwebp/webp"
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 $(inherited) PIN_WEBP=1
HEADER_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/PINCache" "${PODS_ROOT}/Headers/Public/PINRemoteImage" "${PODS_ROOT}/Headers/Public/libwebp"
OTHER_CFLAGS = $(inherited) -isystem "${PODS_ROOT}/Headers/Public" -isystem "${PODS_ROOT}/Headers/Public/PINCache" -isystem "${PODS_ROOT}/Headers/Public/PINRemoteImage" -isystem "${PODS_ROOT}/Headers/Public/libwebp"
OTHER_LDFLAGS = $(inherited) -ObjC -l"Pods-PINRemoteImage Tests-PINCache" -l"Pods-PINRemoteImage Tests-PINRemoteImage" -l"Pods-PINRemoteImage Tests-libwebp" -framework "Accelerate" -framework "Foundation" -framework "ImageIO" -weak_framework "UIKit"
PODS_ROOT = ${SRCROOT}/Pods

View File

@@ -1,6 +0,0 @@
#include "Pods-PINRemoteImage-PINCache.xcconfig"
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/PINCache" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/PINCache" "${PODS_ROOT}/Headers/Public/PINRemoteImage" "${PODS_ROOT}/Headers/Public/libwebp" "${PODS_ROOT}/Headers/Public/libwebp/webp"
OTHER_LDFLAGS = ${PODS_PINREMOTEIMAGE_PINCACHE_OTHER_LDFLAGS}
PODS_ROOT = ${SRCROOT}
SKIP_INSTALL = YES

View File

@@ -2,3 +2,6 @@
#import <UIKit/UIKit.h>
#endif
#ifndef TARGET_OS_WATCH
#define TARGET_OS_WATCH 0
#endif

View File

@@ -1 +1,5 @@
PODS_PINREMOTEIMAGE_PINCACHE_OTHER_LDFLAGS = -framework "Foundation" -weak_framework "UIKit"
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/PINCache" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/PINCache" "${PODS_ROOT}/Headers/Public/PINRemoteImage" "${PODS_ROOT}/Headers/Public/libwebp"
OTHER_LDFLAGS = -framework "Foundation" -weak_framework "UIKit"
PODS_ROOT = ${SRCROOT}
SKIP_INSTALL = YES

View File

@@ -1,6 +0,0 @@
#include "Pods-PINRemoteImage-PINRemoteImage.xcconfig"
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 ${PODS_PINREMOTEIMAGE_PINREMOTEIMAGE_GCC_PREPROCESSOR_DEFINITIONS}
HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/PINRemoteImage" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/PINCache" "${PODS_ROOT}/Headers/Public/PINRemoteImage" "${PODS_ROOT}/Headers/Public/libwebp" "${PODS_ROOT}/Headers/Public/libwebp/webp"
OTHER_LDFLAGS = ${PODS_PINREMOTEIMAGE_PINREMOTEIMAGE_OTHER_LDFLAGS}
PODS_ROOT = ${SRCROOT}
SKIP_INSTALL = YES

View File

@@ -1,2 +1,5 @@
PODS_PINREMOTEIMAGE_PINREMOTEIMAGE_GCC_PREPROCESSOR_DEFINITIONS = $(inherited) PIN_WEBP=1
PODS_PINREMOTEIMAGE_PINREMOTEIMAGE_OTHER_LDFLAGS = -framework "Accelerate" -framework "ImageIO" -framework "UIKit"
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 $(inherited) PIN_WEBP=1
HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/PINRemoteImage" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/PINCache" "${PODS_ROOT}/Headers/Public/PINRemoteImage" "${PODS_ROOT}/Headers/Public/libwebp"
OTHER_LDFLAGS = -framework "Accelerate" -framework "ImageIO" -framework "UIKit"
PODS_ROOT = ${SRCROOT}
SKIP_INSTALL = YES

View File

@@ -1,5 +0,0 @@
#include "Pods-PINRemoteImage-libwebp.xcconfig"
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/libwebp" "${PODS_ROOT}/Headers/Private/libwebp/webp" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/PINCache" "${PODS_ROOT}/Headers/Public/PINRemoteImage" "${PODS_ROOT}/Headers/Public/libwebp" "${PODS_ROOT}/Headers/Public/libwebp/webp"
PODS_ROOT = ${SRCROOT}
SKIP_INSTALL = YES

View File

@@ -0,0 +1,4 @@
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/libwebp" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/PINCache" "${PODS_ROOT}/Headers/Public/PINRemoteImage" "${PODS_ROOT}/Headers/Public/libwebp"
PODS_ROOT = ${SRCROOT}
SKIP_INSTALL = YES

View File

@@ -0,0 +1,84 @@
#!/bin/sh
set -e
echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
SWIFT_STDLIB_PATH="${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}"
install_framework()
{
if [ -r "${BUILT_PRODUCTS_DIR}/$1" ]; then
local source="${BUILT_PRODUCTS_DIR}/$1"
elif [ -r "${BUILT_PRODUCTS_DIR}/$(basename "$1")" ]; then
local source="${BUILT_PRODUCTS_DIR}/$(basename "$1")"
elif [ -r "$1" ]; then
local source="$1"
fi
local destination="${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
if [ -L "${source}" ]; then
echo "Symlinked..."
source="$(readlink "${source}")"
fi
# use filter instead of exclude so missing patterns dont' throw errors
echo "rsync -av --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${destination}\""
rsync -av --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${destination}"
local basename
basename="$(basename -s .framework "$1")"
binary="${destination}/${basename}.framework/${basename}"
if ! [ -r "$binary" ]; then
binary="${destination}/${basename}"
fi
# Strip invalid architectures so "fat" simulator / device frameworks work on device
if [[ "$(file "$binary")" == *"dynamically linked shared library"* ]]; then
strip_invalid_archs "$binary"
fi
# Resign the code if required by the build settings to avoid unstable apps
code_sign_if_enabled "${destination}/$(basename "$1")"
# Embed linked Swift runtime libraries. No longer necessary as of Xcode 7.
if [ "${XCODE_VERSION_MAJOR}" -lt 7 ]; then
local swift_runtime_libs
swift_runtime_libs=$(xcrun otool -LX "$binary" | grep --color=never @rpath/libswift | sed -E s/@rpath\\/\(.+dylib\).*/\\1/g | uniq -u && exit ${PIPESTATUS[0]})
for lib in $swift_runtime_libs; do
echo "rsync -auv \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\""
rsync -auv "${SWIFT_STDLIB_PATH}/${lib}" "${destination}"
code_sign_if_enabled "${destination}/${lib}"
done
fi
}
# Signs a framework with the provided identity
code_sign_if_enabled() {
if [ -n "${EXPANDED_CODE_SIGN_IDENTITY}" -a "${CODE_SIGNING_REQUIRED}" != "NO" -a "${CODE_SIGNING_ALLOWED}" != "NO" ]; then
# Use the current code_sign_identitiy
echo "Code Signing $1 with Identity ${EXPANDED_CODE_SIGN_IDENTITY_NAME}"
echo "/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} --preserve-metadata=identifier,entitlements \"$1\""
/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} --preserve-metadata=identifier,entitlements "$1"
fi
}
# Strip invalid architectures
strip_invalid_archs() {
binary="$1"
# Get architectures for current file
archs="$(lipo -info "$binary" | rev | cut -d ':' -f1 | rev)"
stripped=""
for arch in $archs; do
if ! [[ "${VALID_ARCHS}" == *"$arch"* ]]; then
# Strip non-valid architectures in-place
lipo -remove "$arch" -output "$binary" "$binary" || exit 1
stripped="$stripped $arch"
fi
done
if [[ "$stripped" ]]; then
echo "Stripped $binary of architectures:$stripped"
fi
}

View File

@@ -60,7 +60,7 @@ install_resource()
mkdir -p "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
if [[ "${ACTION}" == "install" ]]; then
if [[ "${ACTION}" == "install" ]] && [[ "${SKIP_INSTALL}" == "NO" ]]; then
mkdir -p "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
fi

View File

@@ -1,5 +1,5 @@
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 $(inherited) PIN_WEBP=1 $(inherited) PIN_WEBP=1
HEADER_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/PINCache" "${PODS_ROOT}/Headers/Public/PINRemoteImage" "${PODS_ROOT}/Headers/Public/libwebp" "${PODS_ROOT}/Headers/Public/libwebp/webp"
OTHER_CFLAGS = $(inherited) -isystem "${PODS_ROOT}/Headers/Public" -isystem "${PODS_ROOT}/Headers/Public/PINCache" -isystem "${PODS_ROOT}/Headers/Public/PINRemoteImage" -isystem "${PODS_ROOT}/Headers/Public/libwebp" -isystem "${PODS_ROOT}/Headers/Public/libwebp/webp"
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 $(inherited) PIN_WEBP=1
HEADER_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/PINCache" "${PODS_ROOT}/Headers/Public/PINRemoteImage" "${PODS_ROOT}/Headers/Public/libwebp"
OTHER_CFLAGS = $(inherited) -isystem "${PODS_ROOT}/Headers/Public" -isystem "${PODS_ROOT}/Headers/Public/PINCache" -isystem "${PODS_ROOT}/Headers/Public/PINRemoteImage" -isystem "${PODS_ROOT}/Headers/Public/libwebp"
OTHER_LDFLAGS = $(inherited) -ObjC -l"Pods-PINRemoteImage-PINCache" -l"Pods-PINRemoteImage-PINRemoteImage" -l"Pods-PINRemoteImage-libwebp" -framework "Accelerate" -framework "Foundation" -framework "ImageIO" -framework "UIKit" -weak_framework "UIKit"
PODS_ROOT = ${SRCROOT}/Pods

View File

@@ -1,5 +1,5 @@
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 $(inherited) PIN_WEBP=1 $(inherited) PIN_WEBP=1
HEADER_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/PINCache" "${PODS_ROOT}/Headers/Public/PINRemoteImage" "${PODS_ROOT}/Headers/Public/libwebp" "${PODS_ROOT}/Headers/Public/libwebp/webp"
OTHER_CFLAGS = $(inherited) -isystem "${PODS_ROOT}/Headers/Public" -isystem "${PODS_ROOT}/Headers/Public/PINCache" -isystem "${PODS_ROOT}/Headers/Public/PINRemoteImage" -isystem "${PODS_ROOT}/Headers/Public/libwebp" -isystem "${PODS_ROOT}/Headers/Public/libwebp/webp"
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 $(inherited) PIN_WEBP=1
HEADER_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/PINCache" "${PODS_ROOT}/Headers/Public/PINRemoteImage" "${PODS_ROOT}/Headers/Public/libwebp"
OTHER_CFLAGS = $(inherited) -isystem "${PODS_ROOT}/Headers/Public" -isystem "${PODS_ROOT}/Headers/Public/PINCache" -isystem "${PODS_ROOT}/Headers/Public/PINRemoteImage" -isystem "${PODS_ROOT}/Headers/Public/libwebp"
OTHER_LDFLAGS = $(inherited) -ObjC -l"Pods-PINRemoteImage-PINCache" -l"Pods-PINRemoteImage-PINRemoteImage" -l"Pods-PINRemoteImage-libwebp" -framework "Accelerate" -framework "Foundation" -framework "ImageIO" -framework "UIKit" -weak_framework "UIKit"
PODS_ROOT = ${SRCROOT}/Pods