views:

2007

answers:

1

In Java

static final int VCount = 21, TCount = 28, NCount = VCount * TCount;

in Objective-C

static int VCount = 21, TCount = 28, NCount = ???;

How can I express the NCount int because it refers to variables?

+5  A: 

Those variable's are not constants. Usually in Objective-C you would define basic constants using the pre-processor and place them in shared header files. For example:

#define VCOUNT 21

Constants created in this way are typically written in all caps. Another convention is to create the symbol in a shared source file (one that everything is linked to) and declare it as an external symbol. Cocoa does this a lit with well-defined key values. For example, in the shared header file, you would define the variable:

extern const NSString *myGlobalKey;

Then in some source file, you define the actual value of the variable (at the file scope):

const NSString *myGlobalKey = @"MyGlobalKey";

If your class is simply using a global, constant variable and the value needs no scope outside your class, it is okay to use any of these techniques and simply not provide definitions for them in any shared header file.

Jason Coco