views:

267

answers:

1

In Java, I can declare local "variables" as final, e.g.

void myMethod() {
    final String foo = "Hello World!";
    foo = "Bye-bye..."; // compile error!!
    return;
}

When I try to change its value, a get an error from the compiler. I want to declare some of my local "variables" final to avoid changing their value by accident.

Is this possible in Objective-C?

+6  A: 

Like in C/C++, use the const keyword.

For more info, this article seems right up your alley: Java Developer’s Guide to String Constants in Objective-C

danben
Thanks for the quick answer. I didn't know that I could also use ``const`` in non-static declarations.
Yang