简体   繁体   中英

error: initializer element is not constant

I've created a new class and i want to declare a NSDictionary containing a table of values so that it's available in the rest of my application.

I did it this way as a property of the class (modified):

NSDictionary *ell = [NSDictionary dictionaryWithObjectsAndKeys:
    [[JFEllipsoid alloc] initWithRadius:6377563.396 withInvF:299.3249646], @"key1",                         
    [[JFEllipsoid alloc] initWithRadius:6377340.189 withInvF:299.3249646], @"key2",
nil};

When i compile i get this error:

error: initializer element is not constant

How/Where can i declare this array of data so that it's available when i instance that class?

See this question:

To make a long story short, you can try declaring your string data as extern const before using them, or you can change the scope of where you're declaring your NSDictionary.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM