3

I have not developed anything for IOS in a long time so please bear with me. Using the Swift language for the first time in XCode 6.3. I have a pre-existing sqlite database, myDB.sqlite, that I want to import into my project.

I have added the sqlite Framework, added FMDB and the bridging header file and then added the myDB.sqlite file to my project. It is also included in "Copy Bundle Resources".

I am just trying to access myDB.sqlite in my bundle directory to copy it to my Documents directory when the app is run for the first time in the Simulator. However it keeps saying it cannot find the file.

In my AppDelegate.swift:

let dbPath = NSBundle.mainBundle().pathForResource("myDB", ofType:"sqlite")

It keeps telling me that dbPath is nil.

2
  • "added the myDB.sqlite file to my project. It is also included in Copy Bundle Resources" But clearly this was not done correctly, since if it were, dbPath would not be nil. Select myDB.sqlite in the Project navigator and use the File inspector to examine its Target membership; is it part of your app target? Commented Jun 12, 2015 at 22:14
  • You are right. Thank you. It has been a VERY long day. I'd accidentally deleted the myDB.sqlite file (as I hadn't physically copied it into my Project folder) while doing some cleaning up and for some reason, Xcode did not mark the file as red (to warn me that it was missing). I copied everything back and it works now. Duh! Thanks for pointing out my stupidity, now I need some zzzz. Commented Jun 12, 2015 at 22:39

1 Answer 1

4

Check the target membership of your SQLite database and it's done:

check

Sign up to request clarification or add additional context in comments.

1 Comment

This should be the accepted answer. Its one of a few things you need to do to access a file (along with potentially copying the resource into the Documents directory as in: stackoverflow.com/questions/53073791/…)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.