[英]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.我在一个文件中有一个 SQL 脚本,添加到我的 Xcode 项目中,我想获取它的文件路径。
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.提前致谢。
To declare new variables inside a switch
statement you need to create a 'block' for them to exist in:要在switch
语句中声明新变量,您需要创建一个“块”让它们存在于:
switch (var){
case 1:
{
NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"triggers.sql"];
...
break;
}
...
}
Try that:试试看:
NSString* databasePathFromApp = [[NSBundle mainBundle] pathForResource:@"triggers.sql" ofType:nil];
//or
NSString* databasePathFromApp = [[NSBundle mainBundle] pathForResource:@"triggers" ofType:@"sql"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.