我有一些代码,我用来打开文本文件,它运作良好,但现在它的一些部分已弃用,所以我改变它们使其工作没有任何错误。 我完成了,这是工作的罚款新的代码,但它给我,我可以不知道如何解决它警告... 这里是我的代码:不兼容的指针类型警告使用NSOpenPanel
-(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 * __强”到类型的参数“NSURL *”
和它出来时,我试图通过的文件中的NSString *内容的内容,但无论如何内容是充满了文件的内容......一切接缝处的工作好... 任何帮助将是非常赞赏...和平 - 马西
你传递一个NSString,其中一个NSURL预计.. – d4Rk
你说的没错......我只是不得不改变的NSString与NSURL,这是确定...感谢! – Blue