24
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]

I used to know that sending a message to the object is kind of calling the method. However, I can't recognize what is NSSearchPathForDirectoriesInDomains. Is it C style function? If yes then why among all message style calls we have thing kind of function?

pkamb
  • 33,281
  • 23
  • 160
  • 191
Pablo
  • 28,133
  • 34
  • 125
  • 215

2 Answers2

19

Yes, it's a plain C function taking and returning objective-c objects.

As to the why... Apple probably didn't find a nice class to put it in. :-) Seriously though, it could be a static method on UIApplication or NSApplication or similar, but it's hard to justify and quite system-specific (you'd have it in NSApplication on OS X and UIApplication on iOS).

Andriy
  • 2,767
  • 2
  • 21
  • 29
Eiko
  • 25,601
  • 15
  • 56
  • 71
  • Can you please answer the comment from above: "why should one use firstObject instead of lastObject? Don't we expect there to be only one result? ". Isn't this suppose to just be a single string-like path like /User/User_name/library/developers/... Why is it an array?! [Eiko sendThankYouMessage] – mfaani Mar 11 '16 at 13:32
  • 1
    @asma22 No, I can't. If there's a difference, it is non-obvious. The only clue in the documentation says "The list is in the order in which you should search the directories", making firstObject the natural choice. The bigger questions are what to do if the array contains zero or more than one object. I have no good idea. – Eiko Mar 11 '16 at 15:23
15

Check out http://www.techotopia.com/index.php/Working_with_Directories_on_iPhone_OS and http://iphonedevelopmentblog.blogspot.com/2011/03/documents-directory-file-path-iphone.html

I was studying the same material, and these links provide exhaustive information on the subject.

Kim Gysen
  • 151
  • 1
  • 3