Question

I had some code I used to open text files and it was working good, but now some parts of it are deprecated so I changed them to make it work without any error. I finished with a new code that it is working fine but it gives me a warning that I can not understand how to fix it... here is my code:

-(IBAction)openMyFile:(id)sender
{
    int i;

    NSOpenPanel* openDlg = [NSOpenPanel openPanel];

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSURL *myUrl = [NSURL fileURLWithPath:documentsDirectory]; //before here I had setDirectory but now is deprecated
    [openDlg setDirectoryURL:myUrl];

    [openDlg setCanChooseFiles:YES];

    [openDlg setCanChooseDirectories:YES];


    if ( [openDlg runModal] == NSOKButton )
    {

        NSArray* files = [openDlg URLs]; // here I had [openDlg filenames] but now is deprecated

        for( i = 0; i < [files count]; i++ )
        {
            NSString* fileName = [files objectAtIndex:i];

            NSString *content = [NSString stringWithContentsOfURL:fileName encoding:NSUTF8StringEncoding error:nil]; //HERE IS WHERE I GET THE WARNING
        }
     }
}

The warning I'm getting says:

incompatible pointer types sending 'nsstring *__strong' to parameter of type 'nsurl *'

and it comes out when I try to pass the content of the file in the NSString *content but anyway content is filled with the content of the file... everything seams to work good... Any help would be very much appreciated... Peace - Massy

Was it helpful?

Solution

[openDlg URLs] returns an array of URLs, not strings:

NSArray *files = [openDlg URLs];
for(i = 0; i < [files count]; i++)
{
    NSURL *fileURL = [files objectAtIndex:i];
    NSString *content = [NSString stringWithContentsOfURL:fileURL encoding:NSUTF8StringEncoding error:nil];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top