Iphone iOS:NSUrl语法

Iphone iOS:NSUrl语法,iphone,objective-c,ios,nsurl,Iphone,Objective C,Ios,Nsurl,我目前有这个代码可以工作。我有两个问题 如何将目录设置为“支持文件” 如何在文件名中使用变量?我需要它来根据变量播放任何动物的mp3 我对Objective-C非常陌生,所以很多语法和一般方法对我来说都是新的。谢谢你的耐心 使用以下命令: NSString *path = [[NSBundle mainBundle] pathForResource:@"Sheep" ofType:@"mp3"]]; NSURL *url = [NSURL fileURLWithPath:path]; 将资源复

我目前有这个代码可以工作。我有两个问题

  • 如何将目录设置为“支持文件”
  • 如何在文件名中使用变量?我需要它来根据变量播放任何动物的mp3
  • 我对Objective-C非常陌生,所以很多语法和一般方法对我来说都是新的。谢谢你的耐心

    使用以下命令:

    NSString *path = [[NSBundle mainBundle] pathForResource:@"Sheep" ofType:@"mp3"]];
    NSURL *url = [NSURL fileURLWithPath:path];
    
    将资源复制到捆绑包时,它们不会保留其目录结构。只要按名称标识资源,它就会找到它的路径

    仅供参考,以下内容也适用:

    NSString *path = [[NSBundle mainBundle] pathForResource:@"Sheep.mp3" ofType:@""]];
    NSURL *url = [NSURL fileURLWithPath:path];
    
    如果您在plist中有一组逻辑上分组在一起的资源,并且您正在以编程方式读取这些资源,那么这可能很有用。例如:

    //  reference to a dictionary with the entry 'Sheep.mp3'
    NSString *resourceName = [dictionary objectForKey:item1]; 
    NSString *path = [[NSBundle mainBundle] pathForResource:resourceName ofType:@""]];
    NSURL *url = [NSURL fileURLWithPath:path];
    
    使用以下命令:

    NSString *path = [[NSBundle mainBundle] pathForResource:@"Sheep" ofType:@"mp3"]];
    NSURL *url = [NSURL fileURLWithPath:path];
    
    将资源复制到捆绑包时,它们不会保留其目录结构。只要按名称标识资源,它就会找到它的路径

    仅供参考,以下内容也适用:

    NSString *path = [[NSBundle mainBundle] pathForResource:@"Sheep.mp3" ofType:@""]];
    NSURL *url = [NSURL fileURLWithPath:path];
    
    如果您在plist中有一组逻辑上分组在一起的资源,并且您正在以编程方式读取这些资源,那么这可能很有用。例如:

    //  reference to a dictionary with the entry 'Sheep.mp3'
    NSString *resourceName = [dictionary objectForKey:item1]; 
    NSString *path = [[NSBundle mainBundle] pathForResource:resourceName ofType:@""]];
    NSURL *url = [NSURL fileURLWithPath:path];
    

    超级的。我有这个,并没有建立,因为我不知道路径是自动解决。。。谢谢超级的。我有这个,并没有建立,因为我不知道路径是自动解决。。。谢谢