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:

  1. 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.

  2. 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

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -