Created
August 24, 2015 04:06
-
-
Save SlaunchaMan/815b3e7214ceb2000e64 to your computer and use it in GitHub Desktop.
Getting around Swift 2’s lack of compatibility with vararg methods for complication text providers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface CLKTextProvider (NNNCompoundTextProviding) | |
+ (nonnull CLKTextProvider *)nnn_textProviderByJoiningProvider:(nonnull CLKTextProvider *)provider1 andProvider:(nonnull CLKTextProvider *)provider2 withString:(nullable NSString *)joinString; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation CLKTextProvider (NNNCompoundTextProviding) | |
+ (nonnull CLKTextProvider *)nnn_textProviderByJoiningProvider:(nonnull CLKTextProvider *)provider1 andProvider:(nonnull CLKTextProvider *)provider2 withString:(nullable NSString *)joinString | |
{ | |
NSString *textProviderToken = @"%@"; | |
NSString *formatString; | |
if (joinString != nil) { | |
formatString = [NSString stringWithFormat:@"%@%@%@", | |
textProviderToken, | |
joinString, | |
textProviderToken]; | |
} | |
else { | |
formatString = [NSString stringWithFormat:@"%@%@", | |
textProviderToken, | |
textProviderToken]; | |
} | |
return [self textProviderWithFormat:formatString, provider1, provider2]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you very much! Just wanted to add how to use it with
CLKRelativeDateTextProvider
: