【发布时间】:2013-05-26 18:40:08
【问题描述】:
我有一些用于打开文本文件的代码,它运行良好,但现在它的某些部分已被弃用,因此我更改了它们以使其正常运行而不会出现任何错误。 我完成了一个工作正常的新代码,但它给了我一个警告,我无法理解如何修复它...... 这是我的代码:
-(IBAction)openMyFile:(id)sender
{
int i;
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSURL *myUrl = [NSURL fileURLWithPath:documentsDirectory]; //before here I had setDirectory but now is deprecated
[openDlg setDirectoryURL:myUrl];
[openDlg setCanChooseFiles:YES];
[openDlg setCanChooseDirectories:YES];
if ( [openDlg runModal] == NSOKButton )
{
NSArray* files = [openDlg URLs]; // here I had [openDlg filenames] but now is deprecated
for( i = 0; i < [files count]; i++ )
{
NSString* fileName = [files objectAtIndex:i];
NSString *content = [NSString stringWithContentsOfURL:fileName encoding:NSUTF8StringEncoding error:nil]; //HERE IS WHERE I GET THE WARNING
}
}
}
我收到的警告说:
不兼容的指针类型将“nsstring *__strong”发送到“nsurl *”类型的参数
当我尝试在 NSString *content 中传递文件的内容时它会出现,但无论如何内容都充满了文件的内容......一切都很好...... 任何帮助将不胜感激......和平 - 马西
【问题讨论】:
-
您正在传递一个 NSString ,其中需要一个 NSURL ..
-
你说得对...我只需要用 NSUrl 更改 NSString 就可以了...非常感谢!
标签: objective-c cocoa nsopenpanel