Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...it was ingeniously designed and all those clicks were for my own good... and that was even before I got my speedy and useful answer to my tekkie question that I eventually posted..."

Geography

Where in the world do Tek-Tips members come from?

Newbie question: NSString goes out of scope when passed to method

joelwyland (Programmer)
22 Oct 09 16:56
Hello,

I'm brand new to Objective-C so I run into things here and there that really confuse me. I'm trying to develop my first iPhone app currently. It works great in the Simulator, but when I install the app onto my iPhone I'm having a problem.

In one of my methods, I initialize an NSString and then pass that string (the filename of a sound file) to another method. I fired up the debugger and discovered that in the first method, the filename is intact and correct, but inside the playSound method the filename parameter is listed as "out of scope" in the debugger.

Any help would be appreciated, but this doesn't make a lot of sense to me. :) I've been coding for many years, but this is my first attempt at Objective-C and I haven't done standard C since college.

Thanks in advance!

CODE

- (IBAction) someMethod {
    
    // a bunch of code snipped ...
    
    NSString *filename = [[NSString alloc] initWithFormat:@"MySound%d.m4v", soundNum];
    [self playSound:filename];
    [filename release];
}


- (void) playSound: (NSString *)filename {
    
    @try {
        NSArray *nameParts = [filename componentsSeparatedByString:@"."];
        
        // a bunch of code snipped...
        
    }

    @catch (NSException *exception) {
        
        NSLog(@"playSound: Caught %@: %@", [exception name], [exception reason]);
        
    }
    
    @finally {
        
    }
    
}
 
theundergod (IS/IT--Management)
31 Dec 09 16:39
At what step is fileName listed as out of scope?

How are you calling the object within the array? With you given code I was able to extract the components of the string and then call on them using
[nameParts objectAtIndex:indexNumber];

without throwing an exception. Not sure what else to possibly suggest really.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close