2
我想转换NSURL
到NSString
在我的程序中的其他地方使用。NSURL到NSString转换做怪事
这里是我的代码:
- (IBAction)openExistingDocument:(id)sender {
NSOpenPanel* panel = [NSOpenPanel openPanel];
[panel setCanChooseDirectories:NO];
[panel setAllowsMultipleSelection:NO];
[panel setMessage:@"Please select a File or Folder containing your character's .png layers"];
[panel beginWithCompletionHandler:^(NSInteger result){
if (result == NSFileHandlingPanelOKButton) {
NSURL* theDoc = [[panel URLs] objectAtIndex:0];
NSString* unformattedURL = [NSString stringWithContentsOfURL:theDoc encoding:NSASCIIStringEncoding error:NULL];
NSString * formattedURL = [unformattedURL stringByReplacingOccurrencesOfString:@"file:/" withString:@""];
NSLog(@"the url says:%@", theDoc);
NSLog(@"the unformatted string says: %@", unformattedURL);
NSLog(@"the formatted string says: %@", formattedURL);
}
}];
}
当我运行程序时,这里就是我的命令行输出:
2012-01-29 18:43:19.205 Cocos2dCharacterRigger[516:407] the url says:file://localhost/Users/*****/Desktop/mockupsite.jpg
2012-01-29 18:43:19.213 Cocos2dCharacterRigger[516:407] the unformatted string says: ÿØÿá.]Exif
2012-01-29 18:43:19.219 Cocos2dCharacterRigger[516:407] the formatted string says: ÿØÿá.]Exif
有人能指出我在做什么错误?
非常感谢你澄清。我希望除了“我觉得自己像一个愚蠢的笨蛋”之外还有别的话要说。 – GreenWire 2012-01-30 01:07:43