Alex Rivera | Logout

Compiler error: "initializer element is not a compile-time constant"

Asked 2011-05-26T18:07:34.160
88

When compiling this code, I get the error "initializer element is not a compile-time constant". Can anyone explain why?

#import "PreferencesController.h"

@implementation PreferencesController

- (id)init
{
    self = [super init];
    if (self) {
        // Initialization code here.
    }

    return self;
}


NSImage* imageSegment = [[NSImage alloc] initWithContentsOfFile:@"/User/asd.jpg"];//error here
Edit
Report

1 Answer

13

Because you are asking the compiler to initialize a static variable with code that is inherently dynamic.

answered 2011-05-26T18:14:02.030

Your Answer