What does “out of scope” mean in the Xcode debugger (for iPhone)?

I load a detailed view of an article when I click on a row in a UITableView. When clicked, it loads an object with data, and I pass that object to the next controller, which is pushed onto the stack. However, when I do this:

- (void)showArticle { [aTitle setText:[[self article] title]]; [aTitle setBackgroundColor:[UIColor clearColor]]; [[self view] addSubview:aTitle]; [aCategory setText:[[self article] category]]; [aCategory setBackgroundColor:[UIColor clearColor]]; [[self view] addSubview:aCategory]; [aAuthors setText:[[self article] authors]]; [aAuthors setBackgroundColor:[UIColor clearColor]]; [[self view] addSubview:aAuthors]; } 

title displayed fine, but category and authors not displayed. When I debug, I get “out of scope” when I look at the values ​​of the category / authors. The article object is @synthesized, and I checked it and it has the correct data.

Any ideas? Does this mean that the method is personal or something?

Thanks!

+4
source share
3 answers

“out of scope” is a common mistake: sometimes this means that the variable is not initialized or this variable has not been released.

This will be if the variable was created in a separate thread without saving.

How do you initialize the article object and where?

Try to save the article object before calling the showArticle method and / or before this line [aCategory setText:[[self article] category]]; .

0
source

This means that the debugger could not see it when it tried to request its value. Sometimes this means that a variable is really out of scope in the sense that it belongs to block C, which you are not in. But there is a glitch when sometimes Objective-C objects, especially NSStrings, appear out of scope when they are really great. This is almost never (in my experience) a programming error.

Try right-clicking on the variable and choosing "print description to console" if you need to see what the real value is.

+7
source

After using this problem for a long time, you should use the object when assigning the userData NSString event as follows:

 @interface callBackData @NSString *text; @NSInteger point; @end 

use it:

 callBackData *data = [[callBackData alloc] init]; data.text=[NSString stringWithString:@"something"]; something.userData = data; 

And you will always be fine.

Pls remember that they don’t directly assign NSString to userData, because someday it will be out of scope for no reason

+1
source

All Articles