Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

DavidBlack

macrumors 6502a
Original poster
Jan 27, 2013
606
239
Somewhere In Apple's HQ ;)
Ok I am making a youtube downloader it works fine and all but I want to implement a NSSAVEPanel. My youtube downloader currently saves the file to the desktop and uses the NSDateFormatter to save the files as the name of the current date. But I want to use a save panel and I am getting trouble.

Code:
  NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
                [dateFormat setDateFormat:@"yyyy-MM-dd-hh-mma"];
                NSString *dateString = [dateFormat stringFromDate: [NSDate date]];
                [dateFormat release];
                
                NSString *randomFilename = [NSString stringWithFormat: @"download_%@", dateString];

Can anyone help me please?
 
Rules of Thumb:
1. Be specific.
2. Post your code.
3. Describe what you expected to happen.
4. Describe what actually happened.

You've done #2 somewhat. In particular, you haven't shown what method or class the posted code resides in. If it's in the wrong method or class, it won't be executed. If that's the problem, then we need to see where it resides, so we understand when it's supposed to be executed.

You haven't done #1, #3, or #4 at all.
 
Do you understand your code or did you simply copy/paste from somewhere?

Yea I understand my code and I wrote it.
1. It takes the current Date format.
2. Then the date is used to name the file. e.g download_2013-05-22-05-36PM.
3. What I want to do is when the user click the download button it will open a save panel then the name that the user chooses I want to put into a string.
Can you help me?
 

Attachments

  • Screen Shot 2013-05-22 at 5.38.37 PM.png
    Screen Shot 2013-05-22 at 5.38.37 PM.png
    13.9 KB · Views: 148
Rules of Thumb:
1. Be specific.
2. Post your code.
3. Describe what you expected to happen.
4. Describe what actually happened.

You've done #2 somewhat. In particular, you haven't shown what method or class the posted code resides in. If it's in the wrong method or class, it won't be executed. If that's the problem, then we need to see where it resides, so we understand when it's supposed to be executed.

You haven't done #1, #3, or #4 at all.
1. It takes the current Date format.
2. Then the date is used to name the file. e.g download_2013-05-22-05-36PM.
3. What I want to do is when the user click the download button it will open a save panel then the name that the user chooses I want to put into a string.
Can you help me?

Also it's a IB Action
 

Attachments

  • Screen Shot 2013-05-22 at 5.41.25 PM.png
    Screen Shot 2013-05-22 at 5.41.25 PM.png
    67.9 KB · Views: 126
Yea I understand my code and I wrote it.
1. It takes the current Date format.
2. Then the date is used to name the file. e.g download_2013-05-22-05-36PM.
3. What I want to do is when the user click the download button it will open a save panel then the name that the user chooses I want to put into a string.
Can you help me?

mmm wrong

you did not write it, thats a project called utubely you got from github.

it does not take the current date format, the code you pasted formats the current date and then appends the formatted date to the name of the file which is then saved to the desktop

if you understand the code, you are familiar with the basics and with the documentation apple provides as well, I am sure:

https://developer.apple.com/library...es/nssavepanel_Class/Reference/Reference.html

The link above gives everything you need, even sample code.


PS: Please, always credit the developer you took the code from
 
mmm wrong

you did not write it, thats a project called utubely you got from github.

it does not take the current date format, the code you pasted formats the current date and then appends the formatted date to the name of the file which is then saved to the desktop

if you understand the code, you are familiar with the basics and with the documentation apple provides as well, I am sure:

https://developer.apple.com/library...es/nssavepanel_Class/Reference/Reference.html

The link above gives everything you need, even sample code.


PS: Please, always credit the developer you took the code from

Thanks I am kinda of embarrassed for lying.
I am a really basic developer i won't even call myself a dev.

----------

mmm wrong

you did not write it, thats a project called utubely you got from github.

it does not take the current date format, the code you pasted formats the current date and then appends the formatted date to the name of the file which is then saved to the desktop

if you understand the code, you are familiar with the basics and with the documentation apple provides as well, I am sure:

https://developer.apple.com/library...es/nssavepanel_Class/Reference/Reference.html

The link above gives everything you need, even sample code.


PS: Please, always credit the developer you took the code from

Can you guide me a little bit more like how to display a NSSave panel?
Thanks
 
Code:
NSSavePanel *savePanel = [NSSavePanel savePanel];
[savePanel setTitle:@"Choose location..."];

NSInteger result = [savePanel runModal];
if (result != NSFileHandlingPanelOKButton)
	return;
		
NSURL *outputURL = [savePanel URL];

Now you have to figure it out
 
Last edited:
Code:
NSSavePanel *savePanel = [NSSavePanel savePanel];
[savePanel setTitle:@"Choose location..."];

NSInteger result = [savePanel runModal];
if (result != NSFileHandlingPanelOKButton)
	return;
		
NSString *outputURL = [savePanel URL];

Now you have to figure it out

Thanks but i don't want the output URL but the name that the user typed as a string.
 
you are going to have to experiment with it, as it is virtually the same code

I already gave you the documents and the code
 
Can you guide me a little bit more like how to display a NSSave panel?

That's why sample code exists. So you can see the whole project, build it, run it, and then look at what the code does.

Sonnestah linked to the class reference doc for NSSavePanel. On that page, located near the top, are links to 5 separate sample code projects. You should be able to download, build, run, and then explore the source code for each one.

The class reference doc also has links to Companion Guides at the left. You should read those to understand the high-level workings, and read the discussion of how to use the class.

If you can't read reference docs or sample code to learn how a class works, then you're trying to work beyond your skill level. You should go back to the fundamental classes, read the reference docs and sample code for them, and learn how things work. The ability to read reference docs and sample code is a fundamental and reusable skill. Without it, you won't get far in programming.
 
you are going to have to experiment with it, as it is virtually the same code

I already gave you the documents and the code

This is what I have
Code:
NSSavePanel *savePanel = [NSSavePanel savePanel];
                [savePanel setTitle:@"Choose location..."];
                
                NSInteger result = [savePanel runModal];
                if (result != NSFileHandlingPanelOKButton)
                    return;
                
                NSString *outputURL = [savePanel URL];
                
                NSString *randomFilename = outputURL;
                
                r = [ASIHTTPRequest requestWithURL: self.extractedURL];
                
                NSString *local_full_path = [ [NSString stringWithFormat: @"~/Desktop/%@.mp4", savePanel] stringByExpandingTildeInPath];
                NSLog(@"Saving to: %@", local_full_path);
                NSLog(@"Saving to the parent folder: %@", [local_full_path stringByDeletingLastPathComponent]);
                [r setTimeOutSeconds: 10];

it works but the output is:
 

Attachments

  • Screen Shot 2013-05-22 at 7.55.41 PM.png
    Screen Shot 2013-05-22 at 7.55.41 PM.png
    13.4 KB · Views: 126
  • Screen Shot 2013-05-22 at 7.54.45 PM.png
    Screen Shot 2013-05-22 at 7.54.45 PM.png
    62.6 KB · Views: 94
theres obviously a mistake I made on the code I gave you

if you read the warning I am sure you're going to be able to fix it.
 
plus you've got the local_full_path wrong

----------

This is the warning.
Thanks for your help so far I am getting closer to getting it to work right.

the highlighted line is
Code:
NSString *outputURL = [savePanel URL];

Read the warning and make the change it says
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.