Eugene Gordin
Eugene Gordin

Reputation: 4107

CALayer _layer is not getting initialized on application startup?! (OSX, Cocoa)

I'm very new to AVFoundation and QuartzCore development and I'm having troubles with CALayers. I'm sorry if this is a silly problem.

Here's my code:

.h

#import <Cocoa/Cocoa.h>
#import <AVFoundation/AVFoundation.h>
#import <QuartzCore/QuartzCore.h>
@interface Document : NSPersistentDocument 
{
    AVPlayer *player;
    AVPlayerLayer *playerLayer;
    NSView *playerView;
}
@property AVPlayerLayer *playerLayer;
@property AVPlayer *player;
@property IBOutlet NSView *playerView;


@end

.m

#import "Document.h"

@implementation Document
@synthesize playerView;
@synthesize player;
@synthesize playerLayer;

- (id)init
{
    self = [super init];
    if (self) {    
    }
    return self;
}

- (NSString *)windowNibName
{
    return @"Document";
}

- (void)windowControllerDidLoadNib:(NSWindowController *)aController
{
    [super windowControllerDidLoadNib:aController];
    [[aController window] setMovableByWindowBackground:YES];

    // HERE the layer is nill, and I don't understand why it's not getting initialized?! 
    [[[self playerView] layer] setBackgroundColor:CGColorGetConstantColor(kCGColorBlack)];
}

+ (BOOL)autosavesInPlace
{
    return YES;
}
@end

Any kind of help is very appreciated!

Upvotes: 0

Views: 107

Answers (1)

matt
matt

Reputation: 535989

If the layer is nil, you should start by suspecting that its parent playerView is nil. Is it? If so, you probably haven't hooked up the outlet in the nib. (I see you have declared playerView as an outlet in your code, but that doesn't mean you've configured the nib correctly.)

Upvotes: 1

Related Questions