Can you extract the text from a CLKRelativeDateTextProvider?
Asked Answered
C

2

7

I'm building up a set of Complications and have come to the CLKComplicationTemplateUtilitarianLargeFlat which only has one textProvider.

I want to display some text, along with a relative date. So I tried doing this:

let date = CLKRelativeDateTextProvider(date: NSDate(), style: style, units: units)  
let template = CLKComplicationTemplateUtilitarianLargeFlat()  
template.textProvider = CLKSimpleTextProvider(text: "next: \(date)")  

But all I get is:

<CLKRelativeDateTextProvider: 0x79860b80>  

Can you extract the raw text from the CLKRelativeDateTextProvider or combine it with a CLKSimpleTextProvider in some way?

Concurrence answered 25/6, 2015 at 14:36 Comment(2)
Anyone figure this out with Swift??? Surprised Obj-C wins here.Neoterism
openradar.me/22396489Neoterism
J
3

Pass in the CLKRelativeDateTextProvider object to the format string, as mentioned in Apple's code:

@interface CLKTextProvider : NSObject <NSCopying>

// By passing one or more CLKTextProviders in the format substitutions, you can add text around the output of a text provider.
+ (CLKTextProvider *)textProviderWithFormat:(NSString *)format, ... NS_FORMAT_FUNCTION(1, 2);

@property (nonatomic) UIColor *tintColor;

@end

Here is an example:

id relativeDate = [CLKRelativeDateTextProvider textProviderWithDate:[NSDate dateWithTimeIntervalSinceNow:12 * 60]
                                                              style:CLKRelativeDateStyleNatural
                                                              units:NSCalendarUnitMinute];

template.textProvider = [CLKTextProvider textProviderWithFormat:@"next: %@", relativeDate];

The time shown in the date provider will still update as time passes without having to refresh anything.

Jonis answered 27/10, 2015 at 19:1 Comment(1)
textProviderWithFormat strangely doesn't appear to be available using Swift?Concurrence
C
-2

With the current version of ClockKit you can not pull any String data from a text provider nor combine 2 or more text providers. The only text providers available to you are:

  • CLKDateTextProvider
  • CLKRelativeDateTextProvider
  • CLKSimpleTextProvider
  • CLKTimeIntervalTextProvider
  • CLKTimeTextProvider

To answer your question you will not be able to display the word "Next" and then a date in your complication. Due to the way ClockKit is designed and the way your complication data should be designed, however, you shouldn't be needing to display "Next" at all. Your complication should be automatically showing the next item from your data relative to the current time.

Columniation answered 6/7, 2015 at 2:6 Comment(1)
It appears this is true for Swift projects, although CLKTextProvider textProviderWithFormat is available if using Obj-CConcurrence

© 2022 - 2024 — McMap. All rights reserved.