资源名称的最大长度是多少?
在我的 XCode 项目中,我将 Sounds 文件夹添加到了 Resources 文件夹中。我在 Sounds 文件夹中放入了几个名称相当长(25-30 个字符)的 MP3 文件。我喜欢描述性的。但是,以下代码因未捕获的异常而阻塞:
fileURL = [[NSURL alloc] initFileURLWithPath:[mainBundle pathForResource:@"really_really_long_name_for_real" ofType:@"mp3"]];
如果我将资源名称更改为“blah.mp3”并将相应的代码行更改为:
fileURL = [[NSURL alloc] initFileURLWithPath:[mainBundle pathForResource:@"blah" ofType:@"mp3"]];
一切正常。
资源名称是否有最大长度?
In my XCode project, I added a Sounds folder to my Resources folder. Into the Sounds folder, I dropped a couple of MP3 files with fairly long names (25-30 chars). I like to be descriptive. However, the following code chokes with an UNCAUGHT EXCEPTION:
fileURL = [[NSURL alloc] initFileURLWithPath:[mainBundle pathForResource:@"really_really_long_name_for_real" ofType:@"mp3"]];
If I change the name of the resource to "blah.mp3" and the corresponding code line to:
fileURL = [[NSURL alloc] initFileURLWithPath:[mainBundle pathForResource:@"blah" ofType:@"mp3"]];
everything works fine.
Is there a max length for a name of a resource?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定 iPhone 上是否与 Mac 上的情况相同,但在 Mac 上,文件不受文件名限制,而是受完整路径长度(1024 字节,IIRC)限制。
(至少,这在 Leopard 上是正确的。我还没有在 10.6+ 上尝试过)
I'm not sure if the same is true on the iPhone as the Mac, but on the Mac files are limited not by the file name, but by the full path length (1024 bytes, IIRC).
(At least, this was true on Leopard. I haven't tried this on 10.6+)
我不认为资源名称有这种类型的限制,因为在我当前的项目中,我将图像保存到文档文件夹中,该文件夹是通过连接 7 到 8 个以上的单词来命名的,这使得我的名称长度约为 60-70 个字符,并且一切对我来说都很好。所以我认为问题在于您在命名文件时使用的特殊字符。因此只需检查这些特殊字符即可。
谢谢,
马杜普
I don't think there is such type of limitation on resource names because in my current project I am saving images to the documents folder which are named by concatenating more than 7 to 8 words which makes my name around 60-70 characters long, and everything is working fine for me. So I think the problem would the use of special characters you have used in naming your files. So just check for these special characters.
Thanks,
Madhup
资源名称的最大长度为 255 个字符。
The maximum length of a resource name is 255 characters.