[Adium-devl] Plugin: Unable to add method to AIPreferenceController using category

Henrik Nyh henrik at nyh.se
Thu May 24 12:55:08 UTC 2007


On 24/05/07, Ofri Wolfus <ofri.wolfus at gmail.com> wrote:
> 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.

Thanks for the quick reply!

I use a full path because '#import "AIPreferenceController.h"' and
'#import <Adium/AIPreferenceController.h>' gives 'No such file or directory'.

> Thinking about it, if you don't actually need any of
> AIPreferenceController's methods, @class AIPreferenceController; is supposed
> to do the trick (i think).

This gives me "error: cannot find interface declaration for
'AIPreferenceController'".

> Try implementing +(void)load in your category and log something there to see
> if your category is actually being loaded.

Seems both categories (the one on NSObject and the one on
AIPreferenceController) are loaded. Both log messages.

> Also, print the value of [self
> class] in your +load implementation to see to what class the runtime is
> attaching your category.

The classes are as expected, but I still get "selector not recognized":

2007-05-24 14:52:35.981 Adium[22296] foobar loaded: AIPreferenceController
2007-05-24 14:52:35.981 Adium[22296] barbaz loaded: NSObject
2007-05-24 14:52:35.982 Adium[22296] FileTransferFoldersPerSenderPlugin loaded!
2007-05-24 14:52:35.982 Adium[22296] BARBAZ!
2007-05-24 14:52:35.982 Adium[22296] *** -[AIPreferenceController
foobar]: selector not recognized [self = 0x592bb0]

Weird.

/ H

> - 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
>
> _______________________________________________
> Adium-devl mailing list
> Adium-devl at adiumx.com
> http://adiumx.com/mailman/listinfo/adium-devl_adiumx.com
>
>




More information about the devel mailing list