Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Getting around Swift 2’s lack of compatibility with vararg methods for complication text providers.
@interface CLKTextProvider (NNNCompoundTextProviding)
+ (nonnull CLKTextProvider *)nnn_textProviderByJoiningProvider:(nonnull CLKTextProvider *)provider1 andProvider:(nonnull CLKTextProvider *)provider2 withString:(nullable NSString *)joinString;
@end
@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