views:

519

answers:

2

I have the following Obj C function that works properly:

 NSString* myfunc( int x )
 {
    NSString *myString = @"MYDATA";

    return myString;        
 }

However if I add code to update a UIImage the compile fails with image1 being unknown. image1 is valid: it's set up in the .h, synthesized and that exact line of code works in a method below this function. Only when I move the line of code up to this function does it fail.

 NSString* myfunc( int x )
 {
    NSString *myString = @"MYDATA";
    image1.image = [UIImage imageNamed:@"image1.png"];  // fails to compile
    return myString;        
 }

Shouldn't image1 be recognized anywhere within this particular .m file?

+8  A: 

myfunc is a C-style function here, not an Objective-C method in your class scope, so you can't see your instance variable image1.

you want to declare it as a method:

- (NSString *)myFuncWithParam:(int)x
{
  ...
}
quixoto
A: 

hi there.

i have a related problem.

i have a global NSString called strMode. in one method i set its value. but in another method, i get an error saying that strMode is "out of scope".

what does that mean?

tnx, Ron

Ron
-1 ask a new question; don't post an answer.
Dave DeLong