On Mon, Aug 15, 2016 at 3:29 AM, Trygve Inda <cocoa...@xericdesign.com> wrote: > I have a Pref Pane and a Screen Saver module. They both share a common > helper class (MyDisplayManager). > > When the pref pane has been loaded and I go into the screen saver (or vis > versa), because the host app is System preferences, I get: > > Class MyDisplayManager is implemented in both.... One of the two will be > used. Which one is undefined. > > The class comes from the same source file. What is the best way to handle > this? I could ignore it because the classes are the same (same source file) > so it should not matter which one is used. > > Is there a better way without duplicating and renaming the class?
IMHO, it depends on how your produce is distributed: - if you're distributed it via an Installation package and the components are installed in /Library, you could use a Framework with the shared class and install it in /Library/Frameworks (and of course use the framework in both your Pref Pane and Screen Saver module). - if the installation is supposed to be done manually or with the user double-clicking the Pref Pane and Screen Saver module to get the OS to install them either for all users or the current user: . you could redefine the class name in the .pch of one project. - you could rename the class after one of the 2 projects has been built and then codesign the new binary. Basically, you scan the executable binary for the name of the class and you replace it with a name of the same length. I'm doing this for screen saver modules who share some code which is within a submodule. - you could parse the Mach-O executable file and parse the appropriate sections (__objc_classname, __objc_classlist, etc.) of the appropriate segments (__TEXT, __DATA, __OBJC) (which depends on the Objective-C version for instance) to find your class name and replace it with a unique name (again same length unless you're looking into rebuilding the entire Mach-O). e.g. __DATA, __objc_classlist contains 64-bit references to struct objc2_class_t records in __DATA, __objc_data. The data record of such a struct will point to a objc2_class_ro_t record in __DATA, __objc_const and the name record of this struct will point to the name of the class in __TEXT, __objc_classname. _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com