0

I want to open a database.sqlite3. Firstly, I need to get a path. But I don't know how to get this path.

I need a relative path.

enter image description here

EDIT: I don't want to use NSBundle. It get a very long path.

I want to use /Users/Voloda2/Projects/facebook/database.sqlite3 Is it possible to get a relative path?

EDIT2: I often change my database. I use Navicat for this operation. If I use NSBundle I have one problem. git did't indexed my database because it didn't lies in project folder. Thus I need to lay my database to project folder.

straight path is /Users/Voloda2/Projects/facebook/database.sqlite3

relative path something like this ../database.sqlite3

Relative path is a path relative to project folder. Is it possible to get a relative path? May be it didn't possible.

1
  • This question is not as bad as to be downvoted. +1 to counter it. Commented Oct 21, 2012 at 15:54

1 Answer 1

3

Assuming you're making a regular OS X/Cocoa app, Xcode will copy the database file to the app bundle. So, you can use the NSBundle class to obtain its path easily:

NSString *databasePath = [[NSBundle mainBundle] pathForResource:@"database" ofType:@"sqlite3"]; 
Sign up to request clarification or add additional context in comments.

3 Comments

H2CO3, please see my comment.
@Voloda2 what's the problem with the path being 'very long'? That's how applications are organized in OS X. Also, to what do you want to obtain a relative path? To the home directory? To the app's bundle directory?
@Voloda2 Why don't you just symlink the file in the project folder to the app bundle? (Btw you can define where your project is as a constant string, then use stringByAppendingPathComponent:.)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.