objective c - Problems passing parameters to a dynamic method (object_addMethod) -
i'm attempting use resolveclassmethod:
, object_addmethod
add new method. things seem working fine in general, parameter doesn't seem coming through.
when pass in parameter, such as:
uifont *font1 = [uifont academyengravedletplainofsize:12.0f];
i 0.0 instead of 12.0 font size in dynamic method. here's output sample below:
createnamedfontimp(uifont, academyengravedletplainofsize:, 0.000000)
what doing wrong here?
@interface uifont (ntnamedfonts) +(uifont *)academyengravedletplainofsize:(int)size ns_available_ios(6_0); @end @implementation uifont (ntnamedfonts) nsstring *targetselectorname = @"academyengravedletplainofsize:"; nsstring *targetfontname = @"academyengravedletplain"; +(bool)resolveclassmethod:(sel)sel { nsstring *selectorname = nsstringfromselector(sel); if ( [selectorname isequaltostring:targetselectorname] ) { class metaclass = object_getclass(self); class_addmethod(metaclass, sel, (imp)createnamedfontimp, "@#:f"); return yes; } else return [super resolveclassmethod:sel]; } static id createnamedfontimp(class class, sel _cmd, cgfloat size) { nslog(@"createnamedfontimp(%@, %@, %f)", nsstringfromclass(class), nsstringfromselector(_cmd), size); uifont *font = [class fontwithname:targetfontname size:size]; return font; } @end
you pass integer float. please show method declaration.
btw: what's reason code? category seems better approach.
btw 2: if remember correctly, have use double.
Comments
Post a Comment