Skip to content

Commit 0428e8c

Browse files
committed
Add TARGET_OS_UIKITFORMAC conditional code
- Still no project support for Mac yet - Update build to xcode 10.2
1 parent 63deaed commit 0428e8c

File tree

14 files changed

+109
-19
lines changed

14 files changed

+109
-19
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
language: objective-c
2-
osx_image: xcode10.1
2+
osx_image: xcode10.2
33
script:
44
./build.sh

Extended/TIPXWebPCodec.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
// Copyright © 2016 Twitter. All rights reserved.
77
//
88

9+
#include <TargetConditionals.h>
10+
11+
#if !TARGET_OS_UIKITFORMAC
12+
913
#import <TwitterImagePipeline/TIPImageCodecs.h>
1014

1115
NS_ASSUME_NONNULL_BEGIN
@@ -27,3 +31,5 @@ FOUNDATION_EXTERN NSString * const TIPXImageTypeWebP;
2731
@end
2832

2933
NS_ASSUME_NONNULL_END
34+
35+
#endif // #if !TARGET_OS_UIKITFORMAC

Extended/TIPXWebPCodec.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
// Copyright © 2016 Twitter. All rights reserved.
77
//
88

9+
#include <TargetConditionals.h>
10+
11+
#if !TARGET_OS_UIKITFORMAC
12+
913
#import <Accelerate/Accelerate.h>
1014
#import <TwitterImagePipeline/TwitterImagePipeline.h>
1115
#import <WebP/decode.h>
@@ -583,3 +587,5 @@ static BOOL TIPXWebPCreateRGBADataForImage(CGImageRef sourceImage,
583587
}
584588

585589
NS_ASSUME_NONNULL_END
590+
591+
#endif // #if !TARGET_OS_UIKITFORMAC

GraphicsRendererSpeed/ViewController.m

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,20 @@ - (NSTimeInterval)_q_scaleSpeedCheckWithImage:(UIImage *)image dimensions:(CGSiz
226226
format = [UIGraphicsImageRendererFormat defaultFormat];
227227
}
228228
format.opaque = !hasAlpha;
229-
if (RenderBehaviorModernForcePrefersWideColorNo == behavior) {
230-
format.prefersExtendedRange = NO;
231-
} else if (RenderBehaviorModernForcePrefersWideColorYes == behavior) {
232-
format.prefersExtendedRange = YES;
229+
if (@available(iOS 12, *)) {
230+
if (RenderBehaviorModernForcePrefersWideColorNo == behavior) {
231+
format.preferredRange = UIGraphicsImageRendererFormatRangeStandard;
232+
} else if (RenderBehaviorModernForcePrefersWideColorYes == behavior) {
233+
format.preferredRange = UIGraphicsImageRendererFormatRangeExtended;
234+
}
235+
#if !TARGET_OS_UIKITFORMAC
236+
} else {
237+
if (RenderBehaviorModernForcePrefersWideColorNo == behavior) {
238+
format.prefersExtendedRange = NO;
239+
} else if (RenderBehaviorModernForcePrefersWideColorYes == behavior) {
240+
format.prefersExtendedRange = YES;
241+
}
242+
#endif
233243
}
234244
format.scale = scale;
235245
}

ImageSpeedComparison/AppDelegate.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ @implementation AppDelegate
2222
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
2323
{
2424
[TIPGlobalConfiguration sharedInstance].logger = self;
25+
#if !TARGET_OS_UIKITFORMAC
2526
[TIPImageCodecCatalogue sharedInstance][TIPXImageTypeWebP] = [[TIPXWebPCodec alloc] init];
27+
#endif
2628
return YES;
2729
}
2830

TIP Sample App/AppDelegate.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
4040
[TIPGlobalConfiguration sharedInstance].serializeCGContextAccess = YES;
4141
[TIPGlobalConfiguration sharedInstance].clearMemoryCachesOnApplicationBackgroundEnabled = YES;
4242
[[TIPGlobalConfiguration sharedInstance] addImagePipelineObserver:self];
43+
#if !TARGET_OS_UIKITFORMAC
4344
[[TIPImageCodecCatalogue sharedInstance] setCodec:[[TIPXWebPCodec alloc] init] forImageType:TIPXImageTypeWebP];
45+
#endif
4446
_imagePipeline = [[TIPImagePipeline alloc] initWithIdentifier:@"Twitter.Example"];
4547
_imagePipeline.additionalCaches = @[self];
4648
[TwitterAPI sharedInstance].delegate = self;
@@ -88,14 +90,18 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
8890
- (void)_private_incrementNetworkOperations
8991
{
9092
if ((++_opCount) > 0) {
93+
#if !TARGET_OS_UIKITFORMAC
9194
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
95+
#endif
9296
}
9397
}
9498

9599
- (void)_private_decrementNetworkOperations
96100
{
97101
if ((--_opCount) <= 0) {
102+
#if !TARGET_OS_UIKITFORMAC
98103
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
104+
#endif
99105
}
100106
}
101107

TIP Sample App/TwitterAPI.m

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,11 @@ - (void)_api_loadAccount:(dispatch_block_t)complete
8080
return;
8181
}
8282

83-
NSInteger iOSMajorVersion = NSProcessInfo.processInfo.operatingSystemVersion.majorVersion;
84-
if (iOSMajorVersion >= 11) { // for when assertions are disabled
85-
NSString *reason = [NSString stringWithFormat:@"\n\n=== iOS %ld not supported ==="
86-
"\nThis TIP Sample App has not yet been upgraded to run on iOS 11 or later;"
87-
"\nit requires iOS Accounts.frameowrk access, which was removed in iOS 11."
88-
"\n===\n\n",
89-
(long)iOSMajorVersion];
83+
if (@available(iOS 11, *)) { // for when assertions are disabled
84+
NSString *reason = @"\n\n=== Current iOS not supported ==="
85+
"\nThis TIP Sample App has not yet been upgraded to run on iOS 11 or later;"
86+
"\nit requires iOS Accounts.framework access, which was removed in iOS 11."
87+
"\n===\n\n";
9088
@throw [NSException exceptionWithName:@"TIPSampleAppRunningOnUnsupportedOSVersion"
9189
reason:reason
9290
userInfo:@{@"OSVersion": NSProcessInfo.processInfo.operatingSystemVersionString}];
@@ -151,7 +149,10 @@ - (void)_api_searchForTerm:(NSString *)term count:(NSUInteger)count complete:(vo
151149
@"adc" : @"phone",
152150
@"q" : term,
153151
};
152+
#pragma clang diagnostic push
153+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
154154
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:requestURL parameters:params];
155+
#pragma clang diagnostic pop
155156
request.account = _account;
156157
preparedRequest = request.preparedURLRequest;
157158
}

TIP Sample App/TwitterSearchViewController.m

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,24 @@ - (void)updateSearchResultsForSearchController:(UISearchController *)searchContr
115115
{
116116
}
117117

118+
#if TARGET_OS_UIKITFORMAC
119+
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
120+
{
121+
[NSObject cancelPreviousPerformRequestsWithTarget:self];
122+
[self performSelector:@selector(_triggerSearch)
123+
withObject:nil
124+
afterDelay:0.5];
125+
}
126+
#endif
127+
118128
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
119129
{
130+
[self _triggerSearch];
131+
}
132+
133+
- (void)_triggerSearch
134+
{
135+
UISearchBar *searchBar = self.searchController.searchBar;
120136
NSString *search = searchBar.text;
121137
_term = search;
122138
_searchController.active = NO;

TIP Swift Sample App/AppDelegate.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate, TIPImagePipelineObserver,
5252
tipConfig.isClearMemoryCachesOnApplicationBackgroundEnabled = true
5353
tipConfig.add(self)
5454

55+
#if !targetEnvironment(UIKitForMac)
5556
let catalogue = TIPImageCodecCatalogue.sharedInstance()
5657
catalogue.setCodec(TIPXWebPCodec.init(), forImageType: TIPXImageTypeWebP)
58+
#endif
5759

5860
self.imagePipeline = TIPImagePipeline(identifier: "Twitter.Example")
5961
self.imagePipeline?.additionalCaches = [self]

TIP Swift Sample App/TwitterSearchViewController.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,28 @@ class TwitterSearchViewController: UIViewController, UISearchResultsUpdating, UI
260260
{
261261
}
262262

263+
#if targetEnvironment(UIKitForMac)
264+
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String)
265+
{
266+
NSObject.cancelPreviousPerformRequests(withTarget: self)
267+
self.perform(#selector(_triggerSearch),
268+
with: nil,
269+
afterDelay: 0.5)
270+
}
271+
#endif
272+
263273
func searchBarSearchButtonClicked(_ searchBar: UISearchBar)
264274
{
275+
self._triggerSearch()
276+
}
277+
278+
@objc
279+
func _triggerSearch()
280+
{
281+
guard let searchBar = self.searchController?.searchBar else {
282+
return
283+
}
284+
265285
let search = searchBar.text
266286
self.term = search
267287
self.searchController!.isActive = false

TwitterImagePipeline/TIPImageTypes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ FOUNDATION_EXTERN NSString * const TIPImageTypeAVCI;
9999
PICT (QuickDraw image)
100100
Not supported by __TIP__ by default,
101101
a custom `TIPImageCodec` would be required to add support.
102+
@note PICT images _ARE_ supported on UIKitForMac
102103
*/
103104
FOUNDATION_EXTERN NSString * const TIPImageTypePICT;
104105
/**

TwitterImagePipeline/TIPImageUtils.m

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ - (instancetype)initWithRendererFormat:(UIGraphicsImageRendererFormat *)format
4040
if (tip_available_ios_12) {
4141
_prefersExtendedRange = (format.preferredRange == UIGraphicsImageRendererFormatRangeExtended);
4242
} else {
43+
#if TARGET_OS_UIKITFORMAC
44+
TIPAssertNever();
45+
#else
4346
_prefersExtendedRange = format.prefersExtendedRange;
47+
#endif
4448
}
4549
_opaque = format.opaque;
4650
_scale = format.scale;
@@ -454,9 +458,14 @@ TIPImageRenderBlock __attribute__((noescape)) renderBlock)
454458
}
455459
if (tip_available_ios_12) {
456460
format.preferredRange = (formatInternal.prefersExtendedRange) ? UIGraphicsImageRendererFormatRangeExtended : UIGraphicsImageRendererFormatRangeStandard;
457-
format.prefersExtendedRange = formatInternal.prefersExtendedRange;
461+
#if !TARGET_OS_UIKITFORMAC
462+
if (tip_available_ios_13) {
463+
} else {
464+
format.prefersExtendedRange = formatInternal.prefersExtendedRange;
465+
}
458466
} else {
459467
format.prefersExtendedRange = formatInternal.prefersExtendedRange;
468+
#endif
460469
}
461470
if (format.scale != formatInternal.scale) {
462471
format.scale = (formatInternal.scale == 0.0) ? [UIScreen mainScreen].scale : formatInternal.scale;

TwitterImagePipelineTests/TIPImageTest.m

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ - (void)runSpeedTest:(NSString *)type options:(TIPImageEncodingOptions)options
313313
for (NSUInteger i = 0; i < 5; i++) {
314314
@autoreleasepool {
315315
float quality = 1.0f - ((i % 10) / 10.0f);
316-
#if TARGET_OS_IOS
316+
#if TARGET_OS_IOS && !TARGET_OS_UIKITFORMAC
317317
if (type == TIPXImageTypeWebP && quality > .99f) {
318318
// Lossless WebP is super slow,
319319
// drop down to 99% in order to give WebP a fighting chance
@@ -676,7 +676,11 @@ - (void)testSavePICT
676676

677677
- (void)testXLoadPICT
678678
{
679+
#if TARGET_OS_UIKITFORMAC
680+
[self runLoadTestForReadOnlyFormat:@"pict" imageType:TIPImageTypePICT];
681+
#else
679682
[self runLoadTestForUnreadableFormat:@"pict"];
683+
#endif
680684
}
681685

682686
- (void)testSpeedPICT
@@ -763,7 +767,7 @@ - (void)testSpeedRAW
763767
// unsupported with read only format
764768
}
765769

766-
#if TARGET_OS_IOS
770+
#if TARGET_OS_IOS && !TARGET_OS_UIKITFORMAC
767771
- (void)testSaveWebP
768772
{
769773
XCTAssertNil([[TIPImageCodecCatalogue sharedInstance] codecForImageType:TIPXImageTypeWebP]);
@@ -779,7 +783,7 @@ - (void)testSaveWebP
779783
}
780784
#endif
781785

782-
#if TARGET_OS_IOS
786+
#if TARGET_OS_IOS && !TARGET_OS_UIKITFORMAC
783787
- (void)testXLoadWebP
784788
{
785789
[self runLoadTestForUnreadableFormat:@"webp"];
@@ -795,7 +799,7 @@ - (void)testXLoadWebP
795799
}
796800
#endif
797801

798-
#if TARGET_OS_IOS
802+
#if TARGET_OS_IOS && !TARGET_OS_UIKITFORMAC
799803
- (void)testSpeedWebP
800804
{
801805
XCTAssertNil([[TIPImageCodecCatalogue sharedInstance] codecForImageType:@"webp"]);
@@ -1029,7 +1033,11 @@ - (void)testImageType
10291033
XCTAssertFalse(TIPImageTypeCanReadWithImageIO(@"com.canon.cr2-raw-image"));
10301034
#endif
10311035

1036+
#if TARGET_OS_UIKITFORMAC
1037+
XCTAssertTrue(TIPImageTypeCanReadWithImageIO(TIPImageTypePICT));
1038+
#else
10321039
XCTAssertFalse(TIPImageTypeCanReadWithImageIO(TIPImageTypePICT));
1040+
#endif
10331041
XCTAssertFalse(TIPImageTypeCanReadWithImageIO(TIPImageTypeQTIF));
10341042
XCTAssertFalse(TIPImageTypeCanReadWithImageIO(TIPImageTypeRAW));
10351043

TwitterImagePipelineTests/TIPTests.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,13 @@ Class TIPTestsImageFetchDownloadProviderOverrideClass()
4747
for (NSBundle *innerBundle in [NSBundle allBundles]) {
4848
if ([innerBundle.bundlePath hasSuffix:@".xctest"]) {
4949
bundle = [NSBundle bundleWithPath:[innerBundle.bundlePath stringByAppendingPathComponent:@"TIPTestsResources.bundle"]];
50-
if (bundle) {
51-
break;
50+
if (!bundle) {
51+
bundle = [NSBundle bundleWithPath:[innerBundle.resourcePath stringByAppendingPathComponent:@"TIPTestsResources.bundle"]];
5252
}
5353
}
54+
if (bundle) {
55+
break;
56+
}
5457
}
5558
}
5659
sBundle = bundle;

0 commit comments

Comments
 (0)