Can't Find iPhone Simulator's SQLite Database : Using Magical Record - iphone

In my application's documents folder, I do not find my SQLite database
Library/Application Support/iPhone Simulator/6.1/"random app
id"/Documents/
^This folder is empty
MagicalRecord seems to be working, I just have no idea how to find the database.
I use the following to set up Magical Record
[MagicalRecord setupAutoMigratingCoreDataStack];
So where does MagicalRecord store its database?

MagicalRecord stores, by default, all data stores in the following location:
{App Folder}/Library/Application Support/{App Name from Info.plist}/{storeName.sqlite}
This is easily accessible from the simulator as well as documents.

You can log your SQlite file location using the following NSPersistentStore MR addition :
[NSPersistentStore MR_urlForStoreName:[MagicalRecord defaultStoreName]]

If you know the name of the sqlite file then just do a search in OSX for that file to find the directory. Otherwise the file was never created.
Make sure you are setting up the CoreData stack correctly as per the documents.
+ (void) setupCoreDataStackWithAutoMigratingSqliteStoreNamed:(NSString *)storeName;

Swift + Xcode 7 + simulator 9.0
Please go to your AppDelegate.swift
change
MagicalRecord.setupCoreDataStackWithStoreNamed("yourDBName.sqlite")
to
MagicalRecord.setupCoreDataStackWithAutoMigratingSqliteStoreNamed("yourDBName.sqlite")
Now you can locate the yourDBName.sqlite at
/Users/userName/Library/Developer/CoreSimulator/Devices/"random app id"/data/Containers/Data/Application/"random app id"/Library/Application Support/ProjectName
There is a useful tool: simPHolders2 (http://simpholders.com)
simPHolders easy to access all application folders

Related

save sqlite3 file of my App

I'm new with dealing with the .sqlite3 in iphone, I created a sqlite3 file in
/Users/myLab/Library/Application Support/iPhone Simulator/5.1/Applications/308C4355-D8EE-4524-A7F9-638DEB68B298/Documents/file.sqlite3
and I inserted the tables into it using Terminal.app and everything works ok with my app.
but when I moved this application to another device, opened by xcode and trying to run it, I discovered that my tables are not found in this .sqlite3 file in another device.
how can I save my tables in .sqlite3 file??
Whereas this much info is adiquate to answer you question though i am providing some checkmarks to check for:
Do you have file.sqlite3 in your app resource folder?
Do you have that given table in that resource file.sqlite3 file?
Have you made any changes to the file.sqlite3 placed in the resource folder while app is running? if yes then try deleting that file.sqlite3 from the resource and add again to the resources.
All these checkpoints may make your app work well.
BestLuck..

How to create sqlite database within bundle during iPhone runtime?

I've tried using sqlite3_open statement, but the database is created at root level of my hard disk.
I can actually try to copy it to the bundle document folder. But,
Where will the database created if I execute it during the iPhone runtime? (Since I use iOS Simulator, it is created on root level).
How to create the database at the documents folder level immediately?
I'm sorry if I can't make myself clear enough, I'm really new working with database and stuffs.
Thank you for your attention.
You can not write to the main bundle, because it is signed with SSL certificate. But you can write to the document directory. Have a look at this link of how to create database at runtime in documents directory - create sqlite db programmatically in iphone sdk
You should create database file template with no content, but with structure, that you plan to use in your app. Add this template to your project Resources folder. Then, when app started, copy that file to Documents folder and use it.

Where is the SQL persistent store created by CoreData?

Can someone help me find where CoreData is storing the SQL file it creates in iOS applications?
So far I've tried "Show package contents" on the .xcdatamodel file and also the .xcodeproj file...No dice!
Is there an editor for looking at the contents of these SQL files?
Cheers.
-A
The url parameter of [NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:url:options:error] specifies the location of the file. Find this call in your code and see where you've stored it. XCode templates will put it into the top of your application documents directory, but you can put it anywhere you like.
Note that Apple considers the contents of this database to be opaque and non-user-modifiable. Playing with the data in your store is likely to cause issues with Core Data.
It's typically saved into your application's documents directory, with the name of your data model.
So, for example, if my data model is called AppData.xcdatamodeld, it will be AppData.sqlite inside my app's document directory. You shouldn't really need to touch the .sqlite file though.
Hope that helps!
Core Data editor --> http://christian-kienle.de/CoreDataEditor/

iPhone - persistent store coming from bundle

The Xcode templates for the creation of core data apps start a new blank sqlite file when the app is started the first time. But suppose I have a database already created that I need to include in the bundle, so, when the app starts the first time it already starts with a populated database.
How should I proceed. Ok, I know that I cannot write the database in the bundle, so I have to copy it to the document's directory. I see this is where the sqlite database created by the app itself is already on. So, that's it? I just overwrite the original file with the one in the bundle at the end of my RootViewController's viewDidLoad method?
If this is the way to go, then I need to build a control method that does that just the first time, right?
It must be a simpler way...
Any ideas?
thanks
You're on the right track with copying the .sqlite file from the application bundle to the documents directory. I used the approach outlined very thoroughly in this blog post by Jeff LaMarche. It deals specifically with providing staring data to an iPhone application, and it worked like a charm in my app.

How to view data stored in Core Data?

I'm creating a Core Data model for my application. I would like to be able to look inside it to see what I have stored in there.
Is there an easier way than searching for the backing store (mine should be SQLite) and reading it from there? Doesn't seem very Apple-esque.
Once your app has run in the simulator and created the persistent store file, you can find the file in your app's Documents directory.
Your app data will be folder inside (~ is your home directory):
~/Library/Developer/CoreSimulator/<device>
In versions prior to XCode 6, the path was:
~/Library/Application Support/iPhone Simulator/User/Applications/
I sort by "Date Modified" to find the app that I just built.
For viewing a SQLite file, check out Base and/or Core Data Editor.
You can also use FireFox's Add-on tool SQLite Manager (FREE). I use it and it works well.
If you are using iOS 10 & Swift get it into your AppDelegate.swift:
let container = NSPersistentContainer(name: "***")
print(container.persistentStoreDescriptions.first?.url)
Then you'll see something like that:
Optional(file:///Users/<SomeUser>/Library/Developer/CoreSimulator/Devices/956F0003-5DA4-4588-97C1-A9A83767F341/data/Containers/Data/Application/9765FDE1-6971-4706-987B-96FBD3F462BF/Library/Application%20Support/***.sqlite)
You can try a little free tool called CoreDataPro. Pretty nice. Here
Core Data Lab is a dedicated Core Data viewer that offers everything to view and analyze the Core Data database of your app, like automatic search for databases, data change tracker, simulator browser, a predicate editor, data editor, a built-in web and image content viewer, and much more.
Info page: https://betamagic.nl/products/coredatalab.html
Free 14-trial: https://betamagic.nl/downloads/Core%20Data%20Lab%20Trial.zip
Diclaimer: I'm the creator of this tool.
I found a free version here:
http://sourceforge.net/projects/sqlitebrowser/files/sqlitebrowser/2.0%20beta1/sqlitebrowser_200_b1_osx.zip/download
Update to this thread, The iphone simulator location has been moved to a different location in Xcode7 and Xcode8. It is now in:
~/Library/Developer/CoreSimulator/...
where ~ is your home directory.
Any of the previous solutions will still work, but you won't be able to find the correct folder if you use the previous links.
Also try sqlite database browser. its free and reflects that fact. very useful though!
cheers.bo
I created a macOS app to browse your Core Data content. It hides Core Data implementation as you see when you use a SQLite browser. Also you can list all your latest run apps and simulators, with this you can easily find the app you are looking for. More info here:
http://www.microedition.biz/simMagnifier
It has other features like access Simulator's folders such as Documents, Application Support, etc. You can check the content of NSUserDefaults too.
The app is not free sorry! but at least you have a 7 days trial.
Here is the full path, apparently it changed since gerry3's answer
~/Library/Application Support/iPhone Simulator/<Simulator>/Applications/<ApplicationID>/Documents/<NAME>.sqlite
So a correct path would like this:
~/Library/Application Support/iPhone Simulator/7.1-64/Applications/C1F3C2E5-987A-4DF7-91EF-955AE6E52621/Documents/TestApp.sqlite
3 Easy Steps
install liya application, its free, Size 3.1 MB, so installs in 1 minute.
Link https://itunes.apple.com/us/app/liya/id455484422?mt=12.
Open Finder, Press "Ctrl + G" OR "CMD + Ctrl + G", Paste ~/Library/Developer/
In Developer Folder, search for your Core Data model name (eg. MyProjectModel).
Open MyProjectModel.d file Or 'MyProjectModel.sqlite' using liya. In liya, select a table, Click on "Run SQL Command".
Done.