سؤال

In an older version of a framework there were two class, A and B, with A being a subclass of B. In the newer version B no longer exists and everything in B (ivars etc.) is now in A. An executable file is linked against the old version, so it looks for _OBJC_IVAR_$_B.ivar. However I need to it work on the new version (I can't recompile it). So is there a way to change the reference to _OBJC_IVAR_$_A.ivar?

هل كانت مفيدة؟

المحلول

There is no way to do this safely. Not only does the symbol need to be resolved, but the runtime is likely to trip over that symbol. Symbol aliasing may work, but it'll be fragile.

The executable that depends on the older version of framework to the point of referring to an ivar symbol directly will require the class layouts to be compatible and that includes having that subclass with those ivars.

When Objective-C "2.0" solved the fragile base class problem, it did not add the ability to move ivars from class to class (because both A and B could have an ivar of the same name -- perfectly valid, though suspect).


If you absolutely must go down this path, you can try aliasing the symbol in the link line. Add an appropriate alias flag to OTHER_LD_FLAGS in the build settings editor:

 -alias symbol_name alternate_symbol_name
             Create an alias named alternate_symbol_name for the symbol symbol_name.  By default the
             alias symbol has global visibility.  This option was previous the -idef:indir option.
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top