Skip to content

Instantly share code, notes, and snippets.

@leoschweizer
Created January 16, 2016 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leoschweizer/5e2fae183fe4cb53dbde to your computer and use it in GitHub Desktop.
Save leoschweizer/5e2fae183fe4cb53dbde to your computer and use it in GitHub Desktop.
Finding the longest method name in your Objective-C runtime environment with Heliograph
#import <OpinionatedC/OpinionatedC.h>
#import <Heliograph/Heliograph.h>
NSArray *classes = [HGClassMirror allClasses];
NSMutableArray *methods = [NSMutableArray array];
[classes each:^(HGClassMirror *each) {
// add the instance methods of the reflected class
[methods addObjectsFromArray:[each methods]];
// add the class methods of the reflected class
[methods addObjectsFromArray:[[each classMirror] methods]];
}];
HGMethodMirror *maxSelector = [methods max:^NSNumber *(HGMethodMirror *each) {
return @(NSStringFromSelector([each selector]).length);
}];
NSLog(@"%@ defined in %@", NSStringFromSelector([maxSelector selector]), maxSelector.definingClass);
// => shapeEffectSingleBlurFrom:withInteriorFill:offset:blurSize:innerGlowRed:innerGlowGreen:innerGlowBlue:innerGlowOpacity:innerShadowRed:innerShadowGreen:innerShadowBlue:innerShadowOpacity:outerGlowRed:outerGlowGreen:outerGlowBlue:outerGlowOpacity:outerShadowRed:outerShadowGreen:outerShadowBlue:outerShadowOpacity:hasInsideShadowBlur:hasOutsideShadowBlur: defined in <HGClassMirror on CUIShapeEffectStack class>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment