Re: XCode Absolute/Relative path
Re: XCode Absolute/Relative path
- Subject: Re: XCode Absolute/Relative path
- From: Andreas Grosam <email@hidden>
- Date: Wed, 18 Jan 2012 11:53:05 +0100
On Jan 18, 2012, at 5:36 AM, Jos Timanta Tarigan wrote:
> Hi,
>
> Recently i created a program that reads file. Last night (and sometimes this morning) iim pretty sure it works fine: the program can read the file. but now it returns error. Then I put the absolute file path and its working again. I'm pretty sure I did not change anything on the xcode settings or my code. Anyone know why this happened? How can i set my program/xcode to check for relative path instead of absolute?
>
>
> thanks in advance.
I suspect your program couldn't find the file at the specified relative path.
This has nothing to do with Xcode. If you specify a relative path, the filesystem will evaluate a corresponding absolute path against the current working directory in order to locate a file. The current working directory is a property of the environment for the application. Since the current working directory can vary, depending on *how* your program will be launched you should avoid to use relative paths if you want to locate files reliable.
If your application is a Cocoa app or links against Core Foundation, you can use NSBundle/CFBundle methods in order to get the paths for various locations relevant for your application, e.g. the application's "Resource" folder, or the executable path.
If you have a console application (not linking against Foundation) and want to access files which are located relative to your application's executable path, you may first get this path. On Mac OS X, iOS or Darwin, you can use for instance function _NSGetExecutablePath (notice the underscore prefix "_"). You need to include #include <mach-o/dyld.h>.
Otherwise, if your console application shall be portable, getting the executable path is more trickier.
Andreas
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden