NSString / NSURL
NSString / NSURL
- Subject: NSString / NSURL
- From: Amy Heavey <email@hidden>
- Date: Sat, 28 Aug 2010 15:58:27 +0100
'm trying to do a fairly simple copy file process, so I select a file,
and it gets copied to a new location. I seem to be mixing up NSString
and NSURL as I keep getting an NSURL error, can anyone point me down
the right path?
This is what I've got at the moment:
- (IBAction)selectImageFile:(id)sender;
{
NSString* defaultImageLocation;
defaultImageLocation = [NSURL fileURLWithPath: [[self
applicationSupportFolder] stringByAppendingPathComponent: @"/images/"]];
// Create the File Open Dialog class.
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
// Enable the selection of files in the dialog.
[openDlg setCanChooseFiles:YES];
// process the files.
if ( [openDlg runModalForDirectory:nil file:nil] == NSOKButton )
{
NSArray* files = [openDlg filenames];
// process file
NSObject *Product;
Product = [[Products selectedObjects] objectAtIndex:0];
NSString* filePath = [files objectAtIndex:0];
NSString* fileName= [filePath lastPathComponent];
NSMutableString* imagePath;
imagePath = defaultImageLocation;
[imagePath stringByAppendingPathComponent:fileName];
[[ NSFileManager defaultManager ] copyItemAtPath:filePath
toPath:imagePath error:nil];
[Product setValue:imagePath forKey:@"productImage"];
}
}
Many Thanks
Amy
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden