Hi,

from the code listed I cannot tell if you alloc'ed memory for your NSString at all?

What is the goal you try to achieve? If you just want to store a single file path... with a global NSString do as along the lines of:

[rawFileName release];
rawFileName = [[NSString alloc] initWithString:[[files objectAtIndex:i] stringByStandardizingPath]]];

Of course that will give you the last of the selected files stored in the rawFileName string object. Alternatively you can use a mutable string and replace the contents with the selected filename.

Maybe that helps to point you in the right directions ...

Volker


Am 26.05.2009 um 15:33 schrieb vinai:


Hi Folks,

I think I am missing something really basic here with NSString. I am trying to store the path of a user-selected file (from an NSOpenPanel) internally so other routines can act on the data within the file. Here's the relevant section of code:

if ([oPanel runModalForDirectory:nil file:nil types:nil] == NSOKButton)
   {
       NSArray * files = [oPanel filenames];

       /* Process files */

       for( i = 0; i < [files count]; i++ )
       {
[rawFileName initWithString: [[files objectAtIndex:i] stringByStandardizingPath]];
           NSLog(@"Logging the file name variable");
           NSLog(rawFileName);

           NSLog(@"Logging the called file path object directly");
           NSLog([[files objectAtIndex:i] stringByStandardizingPath]);
       }
   }

and this is the output from that section of code:

2009-05-26 09:18:41.931 REMI[19710:807] Logging the file name variable
2009-05-26 09:18:41.932 REMI[19710:807] Logging the called file path object directly 2009-05-26 09:18:41.932 REMI[19710:807] /Users/vinai/Desktop/ rawTestData/P04608.7

rawFileName is declared to be an NSString * in my object's header file. So why does printing out the string returned by the stringByStandardizingPath function work okay, but not when initializing an NSString * variable with it ? What would I need to rawFileName so it can be used by other methods in my object ?

Thanks much all.

vinai




_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/volker_lists%40ecoobs.de

This email sent to volker_li...@ecoobs.de

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to