Out Of Scope Error In Iphone
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up NSString out of scope problem? up vote 2 down vote favorite 1 I'm really pulling my hair out, this must be a simple problem, but I just can't see it. I'm just trying to assign a value to a variable from a text field. In my h file I have NSString *currentPass; @property (nonatomic, retain) NSString *currentPass; My m file. @synthesize currentPass; - (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex: (NSInteger)buttonIndex{ if (alertView.tag == AlertPasswordAsk) { UITextField* theTextField = ((UITextField*)[alertView viewWithTag: 5]); currentPass = [NSString stringWithFormat:@"%@", theTextField.text]; if ([theTextField isEditing]) { [theTextField resignFirstResponder]; } } } - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{ NSLog(@"didDismissWithButtonIndex tag=%i", alertView.tag); if (alertView.tag == AlertPasswordAsk) { if(buttonIndex == 1){ NSUserDefaults *myDefaults = [NSUserDefaults standardUserDefaults]; NSString *strPassword = [NSString alloc]; strPassword = [myDefaults stringForKey:@"pass"]; // ######### ERROR OCCURS HERE ######### NSLog(@"currentPass=%@ strPassword=%@", currentPass, strPassword); if (![currentPass isEqualToString:strPassword]) { [6337:207] didDismissWithButtonIndex tag
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up “out of scope” error when iterating an NSMutableArray up http://stackoverflow.com/questions/4184323/nsstring-out-of-scope-problem vote 3 down vote favorite Why am I getting an "out of scope" error whenever I try to access the "url" variable in this loop? for(NSString *url in self.winnerImageURLs) { [mediaItemString appendFormat:@"{\"type\":\"image\",\"src\":\"%@\",\"href\":\"%@\"},", url, url]; } The class of very item in the "self.winnerImageURLs" NSMutableArray comes back as NSCFString so I'm not sure what the dealio is here. Any ideas on what I'm doing wrong??? Thanks iphone objective-c xcode http://stackoverflow.com/questions/2854101/out-of-scope-error-when-iterating-an-nsmutablearray?tab=oldest iphone-sdk-3.0 class-cluster share|improve this question edited May 18 '10 at 5:29 texmex5 3,71611827 asked May 18 '10 at 1:42 wgpubs 3,335113892 1 Sounds like a debugger quirk. Have you tried using NSLog to determine whether the string you're building appears to be correct? –warrenm May 18 '10 at 2:06 Yup. Did NSLog when I added the NSString into the mutable array .. and in debugger ensured that there is a single element in the array of type NSCFString. –wgpubs May 18 '10 at 2:18 1 I'm not sure I understand the problem. If you're concerned about the type itself, NSCFString is the underlying runtime type of instances of NSString and CFString to support bridging between Cocoa frameworks. –warrenm May 18 '10 at 2:51 add a comment| 2 Answers 2 active oldest votes up vote 1 down vote accepted If you're talking about accessing the url variable in the debugger, it happens quite a lot. It's not a problem in itself. share|improve this answer answered May 18 '10 at 9:44 JeremyP 60.1k785122 add a comment| up vote 1 down vote Short anwer is that it is supposed to be like that. A longer answer is that NSString is
blocks and variables, including memory management.Types of VariableWithin the block object’s body of code, variables may be treated in five different ways.You can reference three standard types of variable, just as you would from https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Blocks/Articles/bxVariables.html a function:Global variables, including static localsGlobal functions (which aren’t technically variables)Local variables and parameters from an enclosing scopeBlocks also support two other types of variable:At function level are __block variables. These are mutable https://www.raywenderlich.com/5677/beginning-arc-in-ios-5-part-1 within the block (and the enclosing scope) and are preserved if any referencing block is copied to the heap.const imports.Finally, within a method implementation, blocks may reference Objective-C instance variables—see Object and Block out of Variables.The following rules apply to variables used within a block:Global variables are accessible, including static variables that exist within the enclosing lexical scope.Parameters passed to the block are accessible (just like parameters to a function). Stack (non-static) variables local to the enclosing lexical scope are captured as const variables.Their values are taken at the point of the block expression within the program. In nested blocks, the value out of scope is captured from the nearest enclosing scope. Variables local to the enclosing lexical scope declared with the __block storage modifier are provided by reference and so are mutable.Any changes are reflected in the enclosing lexical scope, including any other blocks defined within the same enclosing lexical scope. These are discussed in more detail in The __block Storage Type. Local variables declared within the lexical scope of the block, which behave exactly like local variables in a function. Each invocation of the block provides a new copy of that variable. These variables can in turn be used as const or by-reference variables in blocks enclosed within the block. The following example illustrates the use of local non-static variables:int x = 123; void (^printXAndY)(int) = ^(int y) { printf("%d %d\n", x, y);}; printXAndY(456); // prints: 123 456As noted, trying to assign a new value to x within the block would result in an error:int x = 123; void (^printXAndY)(int) = ^(int y) { x = x + y; // error printf("%d %d\n", x, y);};To allow a variable to be changed within a block, you use the __block storage type modifier—see The __block Storage Type.The __block Storage TypeYou can specify that
may want to subscribe to my RSS feed or follow me on Twitter. Thanks for visiting!Learn the ins and outs of ARC in iOS 5! Update 10/24/12: If you'd like a new version of this tutorial fully updated for iOS 6 and Xcode 4.5, check out iOS 5 by Tutorials Second Edition! Note from Ray: This is the twelfth iOS 5 tutorial in the iOS 5 Feast! This tutorial is a free preview chapter from our new book iOS 5 By Tutorials. Matthijs Hollemans wrote this chapter - the same guy who wrote the iOS Apprentice Series. Enjoy! This is a post by iOS Tutorial Team member Matthijs Hollemans, an experienced iOS developer and designer. The most disruptive change in iOS 5 is the addition of Automatic Reference Counting, or ARC for short. ARC is a feature of the new LLVM 3.0 compiler and it completely does away with the manual memory management that all iOS developers love to hate. Using ARC in your own projects is extremely simple. You keep programming as usual, except that you no longer call retain, release and autorelease. That's basically all there is to it. With Automatic Reference Counting enabled, the compiler will automatically insert retain, release and autorelease in the correct places in your program. You no longer have to worry about any of this, because the compiler does it for you. I call that freaking awesome. In fact, using ARC is so simple that you can stop reading this tutorial now. ;-) But if you're still skeptical about ARC -- maybe you don't trust that it will always do the right thing, or you think that it somehow will be slower than doing memory management by yourself -- then read on. The rest of this tutorial will dispel those myths and show you how to deal with some of the less intuitive consequences of enabling ARC in your projects. In addition, we'll give you hands-on experience with converting an app that doesn't use ARC at all to using ARC. You can use these same techniques to convert your existing iOS projects to use ARC, saving yourself tons of memory headaches! How It Works You're probably already familiar with manual memory management, which basically works like this: If you ne