Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get file path of a resource (Objective-C)

I had a SQL script in a file, added to my Xcode project, and I want get its file path.

When I write the following:

switch (var){
    case 1:
         NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"triggers.sql"];
    break;

I got the following error:

Expected expression

What am I doing wrong?

Thanks in advance.

like image 216
mzurita Avatar asked Sep 06 '25 02:09

mzurita


1 Answers

To declare new variables inside a switch statement you need to create a 'block' for them to exist in:

switch (var){
    case 1:
    {
        NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"triggers.sql"];

        ...

        break;
    }
    ...
}
like image 170
Wain Avatar answered Sep 08 '25 00:09

Wain