Why is my “current directory” listed as root (“/”) when I run my application standalone?

StackOverflow https://stackoverflow.com/questions/10486056

  •  06-06-2021
  •  | 
  •  

Question

I have an NSLog call which is displaying the current directory I'm using with the NSFileManager in my program.

When running my application in XCODE, my "current Directory" is shown as:

/Users/gsteiner/Desktop/Program Code/Band Manager/build/Debug

This is expected as it is the location of the compiled application. However, if I then go to the finder and double click the compiled application, which is located at the above path, the current directory is showing:

/

or, the root directory.

I would have thought that the "current directory" would be the directory in which the application is contained, but apparently that is not the case.

Can anyone enlighten me to why this is? Is it some type of error, or is that the way it is supposed to be on an application launch. If so, what would be the best way of finding the directory where the compiled application is located?

Thanks!

Était-ce utile?

La solution

One of the security mechanisms and application sandboxing of iOS is setting the working directory of each application as its root. This way no application has access to another application's directory / resources (and surely no access to the system tools).

Take a look at this document for some more knowledge about it.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top