getComplicationDescriptorsWithHandler method for objective-c

I'm trying to use this objective-c method and have gone to the developer documentation page for information on how to use it. However, in the objective-c documentation version of this method it uses Swift, not objective-c. (Ok, the method declaration is in objective-c, but not the example that follows). Doc page here: https://developer.apple.com/documentation/clockkit/clkcomplicationdatasource/3555131-getcomplicationdescriptorswithha?language=occ

I'm trying to do exactly what the example does on this documentation page, but for objective-c, i.e., set up the complication descriptors and pass them through the handler.

Anyone have an example of how to do this for objective-c?
Answered by Frameworks Engineer in 668242022
You should be able to do this in Objective-C similarly to as follows

Code Block objc
- (void)getComplicationDescriptorsWithHandler:(void (^)(NSArray<CLKComplicationDescriptor *> *))handler {
NSArray<NSNumber *> *mySupportedFamilies = CLKAllComplicationFamilies();
// Create the condition descriptor
CLKComplicationDescriptor *conditionDescriptor = [[CLKComplicationDescriptor alloc] initWithIdentifier:complicationConditionIdentifier displayName:@"Weather Condition" supportedFamilies:mySupportedFamilies];
// ... Create the other descriptors.
// Call the handler and pass an array of descriptors.
handler(@[conditionDescriptor, temperatureDescriptor, precipitationDescriptor]);
}


Accepted Answer
You should be able to do this in Objective-C similarly to as follows

Code Block objc
- (void)getComplicationDescriptorsWithHandler:(void (^)(NSArray<CLKComplicationDescriptor *> *))handler {
NSArray<NSNumber *> *mySupportedFamilies = CLKAllComplicationFamilies();
// Create the condition descriptor
CLKComplicationDescriptor *conditionDescriptor = [[CLKComplicationDescriptor alloc] initWithIdentifier:complicationConditionIdentifier displayName:@"Weather Condition" supportedFamilies:mySupportedFamilies];
// ... Create the other descriptors.
// Call the handler and pass an array of descriptors.
handler(@[conditionDescriptor, temperatureDescriptor, precipitationDescriptor]);
}


Thanks to Frameworks Engineer's reply, it worked!
getComplicationDescriptorsWithHandler method for objective-c
 
 
Q