Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Septimus P

macrumors newbie
Original poster
Sep 29, 2008
3
0
Hi,

I have written a class and declared a variable. How can I reach it with different messages?

Interface-File Deklarations:

int value;

- (void)valueHasChanged:(int)v;
- (void)showIt;

Implementation-File:

- (void)valueHasChanged:(int)v {
value = v;
}

- (void)showIt {
NSString *sendtext = [NSString stringWithFormat:mad:"%i", value];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:sendtext message:mad:" Here it is! " delegate:self
cancelButtonTitle:mad:"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
 

firewood

macrumors G3
Jul 29, 2003
8,141
1,384
Silicon Valley
Obj-C is just a wrapper around C. You can declare and instantiate global variables (and functions) outside the class definitions, just as in standard C. Then access them from anywhere they are declared (as an extern maybe).

Look for a C programming language primer for examples.

.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.