Re: Customising NSFontManager
Re: Customising NSFontManager
- Subject: Re: Customising NSFontManager
- From: Roland King <email@hidden>
- Date: Wed, 18 Nov 2015 09:12:51 +0800
> On 18 Nov 2015, at 09:00, Graham Cox <email@hidden> wrote:
>
>>
>> On 18 Nov 2015, at 11:46 AM, Roland King <email@hidden> wrote:
>>
>>
>>> On 18 Nov 2015, at 08:26, Graham Cox <email@hidden> wrote:
>>>
>>>
>>> Anyone know what NSFontManager’s designated initializer is?
>>>
>>> I have set the Font Manager’s factory class to my subclass of NSFontManager is previously discussed, but its -init method is never called. The Font Manager object is part of MainMenu.xib, which has ‘prefer coder’ unchecked. In any case, NSFontManager doesn’t implement NSCoding so it does not appear to expect -initWithCoder: anyway.
>>>
>>> —Graham
>>>
>>>
>>
>> The documentation claims it’s init()
>>
>> "Your font manager class should implement init as its designated initializer.”
>
>
> Hmmm, oddly enough the documentation set I have does not mention this anywhere that I can see.
>
Sorry it’s a bit early here - I should have said that was the documentation for +setFontManagerFactory - which in my docset at least says init() is the method.
>
>>
>> It also seems to indicate that having it part of MainMenu.xib is too late
>
>> "This method must be invoked before your application’s main nib file is loaded, such as in the application delegate’s applicationWillFinishLaunching: method.”
>
> That statement is self contradictory. The app’s delegate is part of the MainMenu.xib, generally speaking, so that method can’t be invoked before the nib is loaded. In any case, experiemnt bears out that the factory class has to be set in main().
>
> The standard app template puts the Font Manager in MainMenu.xib by default as well, I think - it’s been a very long time since this app was new so things might have changed in that regard. However, it’s too late to change that because I directly connect some things, such as items in the standard Text menu, to the Font Manager instance.
>
> I was setting the factory class in main() and getting the right object class at runtime, but my -init method was never called. If I change the class type in IB to my subclass, then its init method is now called. If I then remove the setting of the factory class from main(), then I get a NSFontManager instance even though the class in IB is something else. So for some reason, I need to do both to get the right class and have it inited correctly. This seems weird to me - maybe the Font Manager is a special case or I’m not propery understanding what’s going on (very likely).
I don’t understand some of that either - it looks to me that setting the factory class in main should be enough and init() should be called. One thought about why it doesn’t work if you put it in the XIB file *only*, is the class itself referenced in your code anywhere or only in the XIB? If the class isn’t referenced in code, it’s not linked into the binary and when the XIB loads it falls back to the superclass. I have more than one project with a stub piece of code, which doesn’t do anything, but is linked in just to get the code for a NIB-only object in the binary. Here’s one of them, I don’t even think I ever call loadClasses, its existence is enough.
@interface LINKERHACK : NSObject
+(void)loadClasses;
@end
@implementation LINKERHACK
+(void)loadClasses
{
Class __unused class1 = [ RKTouchLabelView class ];
Class __unused class2 = [ RKMultiColoredBar class ];
}
@end
>
> —Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden