On 15 Aug 2016, at 03:29, 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?

Source file doesn't matter, it's the executable they're in. The "correct" 
solution would be to have a Framework that both link against. That way, the OS 
knows it's the same thing and loads it only once and links both to it. Of 
course, that only works if it is actually the same framework on disk. 
Otherwise, you may still get the loader seeing them as different (which is the 
only sane thing Apple can do, apart from checksumming both and thereby 
verifying they are actually identical, they really have no way they're the same 
version). So you'd probably need an installer that installs all three into 
predictable locations where they can find each other.

If you can't do that, the only thing you can do is have several different 
copies with different names. a #define in a precompiled header would work. You 
can have a separate header file containing all the shared stuff from any 
precompiled header you might have had before. That way, your PCH could look 
like this:

   #define MYScreenSaverAndPrefPaneHelperClass  
MYPrefPanesScreenSaverAndPrefPaneHelperClass
   #include "MyAppPrefix_Common.pch"

Just keep in mind that this define won't be picked up by any XIBs you're using. 
So if your class gets instantiated by a XIB, you need two versions, or at least 
a shell script build phase that does the same name replacement on the XIB and 
then manually feeds the result through ibtool. If your class only is the file's 
owner of a XIB, then you needn't bother. The file's owner's class is only 
advisory (you get whatever kind of object was passed in as owner when loading 
the XIB).

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://stacksmith.org





_______________________________________________

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

Reply via email to