NSHomeDirectory confusion from Apple docs

Discussion in 'Mac Programming' started by zippyfly, Sep 13, 2009.

  1. zippyfly macrumors regular

    Joined:
    Mar 22, 2008
    #1
    I am confused by the Apple documentation for low-level file handling:

    http://tinyurl.com/q5bzo3

    For the example:

    Code:
    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"MyFile.txt"];
    I just want the home directory, and not appending anything to it.

    I tried

    Code:
    NSString *path = [NSHomeDirectory()];
    but Xcode gives an error of expecting : before ] and so I take it is expecting some parameter to be passed.

    I tried passing an empty string literal @"", and it worked, but surely that is not the right way to do it (?)

    Clicking on the hyperlink for NSHomeDirectory gives a fairly useless description:

    NSHomeDirectory

    Returns the path to the current user’s home directory.

    NSString * NSHomeDirectory (void);

    Return Value

    The path to the current user’s home directory.
    Discussion

    For more information on file-system utilities, see Low-Level File Management Programming Topics.
    Availability

    * Available in Mac OS X v10.0 and later.

    See Also

    * NSFullUserName
    * NSUserName
    * NSHomeDirectoryForUser

    Related Sample Code

    * Quartz Composer WWDC 2005 TextEdit

    Declared In
    NSPathUtilities.h

    Please advise where I should be looking, because I have tried searching in all the usual places (including option+double clicking) and the docs are not helpful.

    Thanks!
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    NSHomeDirectory is a function that returns a NSString*. You have placed the call to the function in square brackets indicating that you want to pass a message to that object but not supplied a message to pass. That's exactly what XCode has told you

    You just want:
    Code:
    NSString *path = NSHomeDirectory();
    
     
  3. zippyfly thread starter macrumors regular

    Joined:
    Mar 22, 2008

Share This Page