NSString 到 FSRef 转换不起作用
对于我的应用程序,我需要使用 Carbon 文件管理器 API 来获取文件夹的大小(NSEnumerator 很慢,并且使用带有 shell 命令的 NSTask 更糟糕)。 我已经导入了 Carbon 框架,并且使用此方法来获取文件夹的大小:
http://www.cocoabuilder.com/archive/message/cocoa/2005/5/20/136503
它使用 FSRef 作为参数,我的路径字符串当前是一个 NSString。 我尝试使用它将 NSString 转换为 FSRef:
FSRef f;
OSStatus os_status = FSPathMakeRef((const UInt8 *)[filePath fileSystemRepresentation], &f, NULL);
if (os_status != noErr) {
NSLog(@"fsref creation failed");
}
然后我调用了文件夹大小方法:
[self fastFolderSizeAtFSRef:f];
但是,当我尝试构建时,我收到了与上述行有关的错误:
error: incomplete type for argument one of 'fastFolderSizeAtFSRef:'
Any帮助将不胜感激。 谢谢
For my app I need to use the Carbon file manager API to get the size of a folder (NSEnumerator is slow, and using NSTask with a shell command is even worse). I've imported the Carbon framework, and I'm using this method to get the size of a folder:
http://www.cocoabuilder.com/archive/message/cocoa/2005/5/20/136503
It uses an FSRef as an argument, and my path string is currently an NSString. I tried using this to convert the NSString to an FSRef:
FSRef f;
OSStatus os_status = FSPathMakeRef((const UInt8 *)[filePath fileSystemRepresentation], &f, NULL);
if (os_status != noErr) {
NSLog(@"fsref creation failed");
}
And then I called the folder size method:
[self fastFolderSizeAtFSRef:f];
However when I try to build, I get this error regarding the above line:
error: incompatible type for argument one of 'fastFolderSizeAtFSRef:'
Any help would be appreciated. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“fastFolderSizeAtFSRef”方法采用 FSRef*(FSRef 指针)。 你给它一个 FSRef。 幸运的是,这是一个单一角色的修复。 您已经:
只需将其更改为:
然后您就可以开始了。 然而,我昨天实现了同样的方法,但在创建 FSRef 本身时遇到了麻烦。 我最终使用了以下代码:
这对我来说工作完美。
编辑:我刚刚开源了我正在使用的代码。这些文件是:
此文件向 NSFileManager 添加了一个方法,该方法使用 FSRef 来查找目录的完整大小。
此文件向 NSString 添加了一个方法,将其转换为 FSRef.
一切都发生在该文件的第 46 行。
The "fastFolderSizeAtFSRef" method takes an FSRef* (FSRef pointer). You're giving it an FSRef. It's a one character fix, luckily enough. You have:
Simply change that to:
And you should be good to go. However, I was implementing this same method yesterday but was having trouble creating the FSRef itself. I eventually went with the following code:
This has been working flawlessly for me.
EDIT: I just open sourced the code that I'm using this in. It's these files:
This file adds a method to NSFileManager that uses an FSRef to find the complete size of a directory.
This file adds a method to NSString that will convert it to an FSRef.
Everything happens on line 46 of this file.