[Adium-devl] Plugin: Unable to add method to AIPreferenceController using category
Ofri Wolfus
ofri.wolfus at gmail.com
Thu May 24 12:41:43 UTC 2007
At first glance your code looks fine except that #import "/Users/
henrik/Documents/Code/Cocoa/adium-1.0.2/Source/
AIPreferenceController.h" line. Why do you use a full path? #import
"AIPreferenceController.h" or #import <Adium/
AIPreferenceController.h> should do it. Thinking about it, if you
don't actually need any of AIPreferenceController's methods, @class
AIPreferenceController; is supposed to do the trick (i think).
Try implementing +(void)load in your category and log something there
to see if your category is actually being loaded. Also, print the
value of [self class] in your +load implementation to see to what
class the runtime is attaching your category.
- Ofri
- - - - - - - - - - - - - - - - - - -
http://www.dpompa.com
- - - - - - - - - - - - - - - - - - -
On 24/05/2007, at 15:25, Henrik Nyh wrote:
> I'm rather new at Cocoa/Objective-C, so please bear with me.
>
> I would like to write an Adium plugin that sticks incoming files in
> per-sender subdirectories of the download folder. So I might get
> "~/Incoming/IM/John Doe (ICQ)/pic.jpg" and so on.
>
> Having poked through the Adium source, I figured a good way to achieve
> this might involve overriding AIPreferenceController's
> -userPreferredDownloadFolder method. (If you have a better idea,
> please let me know.)
>
> However, I'm unable to override that method (using a
> category/swizzling). In fact, I'm unable to add any methods to the
> AIPreferenceController class.
>
> Any idea what I'm doing wrong?
>
> In the following test case, I can add and call methods on NSObject
> fine using categories, but when I call the method that I (thought I)
> added to AIPreferenceController, I get "selector not recognized".
>
>
> //// FileTransferFoldersPerSenderPlugin.h
>
> #import <Cocoa/Cocoa.h>
> #import <Adium/AIPlugin.h>
> #import <Adium/AIAdiumProtocol.h>
> #import <Adium/AIPreferenceControllerProtocol.h>
> #import "/Users/henrik/Documents/Code/Cocoa/adium-1.0.2/Source/
> AIPreferenceController.h"
>
> // Add "foobar" to AIPreferenceController
>
> @interface AIPreferenceController (MyCat)
> - (void)foobar;
> @end
>
> @implementation AIPreferenceController (MyCat)
> - (void)foobar {
> NSLog(@"FOOBAR!");
> }
> @end
>
>
> // Add "barbaz" to NSObject
>
> @interface NSObject (MyCat)
> - (void)barbaz;
> @end
>
> @implementation NSObject (MyCat)
> - (void)barbaz {
> NSLog(@"BARBAZ!");
> }
> @end
>
>
> // Plugin proper
>
> @interface FileTransferFoldersPerSenderPlugin : AIPlugin {
> }
> @end
>
>
>
> //// FileTransferFoldersPerSenderPlugin.m
>
> #import "FileTransferFoldersPerSenderPlugin.h"
>
> @implementation FileTransferFoldersPerSenderPlugin
>
> - (void)installPlugin {
>
> NSLog(@"FileTransferFoldersPerSenderPlugin loaded!");
>
> // This works:
> [[adium preferenceController] barbaz];
>
> // This doesn't:
> [(AIPreferenceController *)[adium preferenceController] foobar];
> // *** -[AIPreferenceController foobar]: selector not recognized
> [self = 0x5a6f00]
>
> }
>
> - (void)uninstallPlugin {
> NSLog(@"FileTransferFoldersPerSenderPlugin unloaded!");
> }
>
> @end
>
>
> Grateful for any help,
> Henrik N
>
> _______________________________________________
> Adium-devl mailing list
> Adium-devl at adiumx.com
> http://adiumx.com/mailman/listinfo/adium-devl_adiumx.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://adium.im/pipermail/devel_adium.im/attachments/20070524/96b97ce6/attachment-0001.html>
More information about the devel
mailing list