Q:

Setting the font of an NSTextView

I am subclassing NSTextView to set it's default font:
PTNfoEditField.h
@interface PTNfoEditField : NSTextView {

}

@end

PTNfoEditField.m
@implementation PTNfoEditField

-(id)init {
    if(self = [super init]) {
        [[self textStorage] setFont:[NSFont fontWithName:@"Courier" size:10]];
    }

    return self;
}

@end

However, this does not work and I don't know how to do it in a different way. Can anyone help me? Thanks.

A:

The initializer for views is not init, it's initWithFrame:. Furthermore, if your view is in a nib, you must also override initWithCoder:. Don't forget to make sure your view is actually a PTNfoEditField, not a regular NSTextView.
Also, you should use [NSFont userFixedPitchFontOfSize:0.0] to set the font. You should hard-code neither the font name (the user may prefer a better monospaced font) nor the font size (the user may find 10-pt hard to read or have their anti-aliasing threshold set above it).

