我正在使用 OpenPanel 来获取文件路径 URL。这有效:
[oPanel beginSheetModalForWindow:theWindow completionHandler:^(NSInteger returnCode)
{
NSURL *pathToFile = nil;
if (returnCode == NSOKButton)
pathToFile = [[oPanel URLs] objectAtIndex:0];
}];
这不会,导致“分配只读变量”错误:
NSURL *pathToFile = nil;
[oPanel beginSheetModalForWindow:theWindow completionHandler:^(NSInteger returnCode)
{
if (returnCode == NSOKButton)
pathToFile = [[oPanel URLs] objectAtIndex:0];
}];
return pathToFile;
通常,从 oPanel 的上下文中提取 pathToFile 的任何尝试都失败了。这对于小情况来说并不是什么大问题,但是随着代码的增长,我不得不将所有东西——XML 解析、核心数据等——塞进一个不合适的区域。我该怎么做才能提取 pathToFile?
谢谢。