Weak Link My Own Objective-C Class -
is possible weak link own objective-c classes?
i have seen can weak link function or variable…
extern int myfunction() __attribute__((weak_import)); extern int myvariable __attribute__((weak_import));
i have this…
if ([myuploadmanager class]) { self.uploadbutton.hidden = no; }
… , able compile if uploadmanager.m not included in project.
to weak link class e.g. myuploadmanager
in own executable:
to keep linker happy, add
other linker flags
in project:-wl,-u,_objc_class_$_myuploadmanager
this allows class symbol undefined if not built executable. considered dynamic lookup instead, same dynamic library symbol.
to keep runtime happy, add class header:
__attribute__((weak_import)) @interface myuploadmanager
when dynamic linker runs, substitutes
nil
class symbol rather crashing.
now can run without either linker or runtime errors:
if ([myuploadmanager class]) { self.uploadbutton.hidden = no; }
note: of xcode 7, -u
linker options conflicts bitcode, may not able use technique future projects.
Comments
Post a Comment