Re: Extending already loaded objects using plugins?
Re: Extending already loaded objects using plugins?
- Subject: Re: Extending already loaded objects using plugins?
- From: Brendan Younger <email@hidden>
- Date: Sat, 15 Jan 2005 13:35:26 -0600
What you have to remember is that, in each running application, there can only be one definition of a specific class. Hence adding the code for "MyObject" to your plug-in means that when the plug-in is loaded, the loader is confronted with two (possibly different) definitions of "MyObject". To avoid breaking the code that is already running, it will simply not load the class from your plug-in or for that matter, the category.
Since you have the code to MyObject, you'll need to put it into a framework and have both the application and the plug-in link against the framework for their definition on MyObject. If you don't want to do this, you can replace the method yourself using the objc_* functions. There's some sample code at <http://cocoadev.com> under the name "Method Swizzling" and in your case, you'll need to do a bit more work since the method can't live in a category on MyObject. Email me off-list if you need sample code for this. However, the best method is to use a shared framework.
Brendan Younger
On Jan 15, 2005, at 1:11 PM, Mont Rothstein wrote:
Where is your category? I assume because you refer to a plugin that it is in a separate bundle.
This bundle (the plugin) needs to link against whatever contains the original MyObject. Usually MyObject would be in a framework, which your application would also link against.
You need to tell you application where to find the bundle using +bundleWithPath: and then to load the bundle using -load.
Hope that helps,
-Mont
On Jan 15, 2005, at 6:53 AM, עפרי וולפוס wrote:
Hi,
I'm trying to extend an already loaded object with a category from a plugin.
I mean lets assume that the program has an object called MyObject and that it has the method - (void)doSomething.
i want that when my plugin is loaded it will replace the -doSomething method with another one.
now i'm trying to do it like this:
@interface MyObject (Additions)
- (void)doSomething;
@end
@implementation MyObject (Additions)
- (void)doSomething
{
...
}
@end
the problem is that in this way, the plugin wouldn't compile and i'm getting the error "Undefined symbols: .obj_class_name_MyObject" but if i include both "MyObject.h" and "MyObject.m" with the plugin, it simply does nothing and use the original implementation of -doSomething.
what am i doing wrong?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden