1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Nssavepanel question

Discussion in 'Mac Programming' started by DavidBlack, May 21, 2013.

  1. macrumors 6502a

    DavidBlack

    #1
    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?
     
  2. macrumors 603

    #2
    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.
     
  3. macrumors regular

    #3
    Do you understand your code or did you simply copy/paste from somewhere?
     
  4. macrumors 6502a

    DavidBlack

    #4
    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?
     

    Attached Files:

  5. macrumors 6502a

    DavidBlack

    #5
    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
     

    Attached Files:

  6. macrumors regular

    #6
    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
     
  7. macrumors 6502a

    DavidBlack

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

    ----------

    Can you guide me a little bit more like how to display a NSSave panel?
    Thanks
     
  8. Sonnestah, May 22, 2013
    Last edited: May 22, 2013

    macrumors regular

    #8
    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
     
  9. macrumors 6502a

    DavidBlack

    #9
    Thanks but i don't want the output URL but the name that the user typed as a string.
     
  10. macrumors regular

    #10
    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
     
  11. macrumors 603

    #11
    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.
     
  12. macrumors 6502a

    DavidBlack

    #12
    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:
     

    Attached Files:

  13. macrumors regular

    #13
    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.
     
  14. macrumors 6502a

    DavidBlack

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

    Attached Files:

  15. macrumors regular

    #15
    plus you've got the local_full_path wrong

    ----------

    the highlighted line is
    Code:
    NSString *outputURL = [savePanel URL];
    Read the warning and make the change it says
     
  16. macrumors 6502a

    DavidBlack

    #16
    Can you help me?
    :confused:
     
  17. macrumors 6502a

    DavidBlack

    #17
    BTW This is the NSLOG MESSAGES
     

    Attached Files:

  18. macrumors 6502a

    DavidBlack

    #18
    And btw how to correct the local_full_path.
     
  19. macrumors 6502a

    DavidBlack

    #19
    I don't understand what the warning is telling me. :confused:

    ----------

    I don't understand what the warning is telling me.
     

Share This Page