constraint issue in sqlite - ios

i am creating database in sqlite i create new database with constraint notnull and unique and save it to the place where is my application then i add things from my application and i check them in Library, Application support/.../..../... when i check database which is just created there then there this database is without Constraint and it accept same data.
why this is happening?
how can i make this database with Constraints just same like i have created while making application database
yes i have tried deleting database and making again
plz suggest something

One of two problems generally causes this sort of behavior (where you're updating a database and you're not seeing this propagated to the app):
The db in the bundle is not getting updated. You can check this by running app on simulator, opening bundle (go to the app in Finder, ~/Library/Application Support/iPhone Simulator/..., and select the app itself and choose "Show Package Contents"), and examining the db directly at that location. Bottom line, Xcode sometimes does not update the bundle properly for files altered outside of Xcode itself. This is fixed by selecting "Clean" from Xcode's "Product" menu, and then rebuilding and reinstalling the app.
The db that app is loading is not a copy of the version in the bundle. It doesn't sound like this is your problem, but many first time developers will copy the db from bundle to Documents folder if the file is not already there, neglecting to remember that when you install the app again, the contents of the Documents folder is preserved, and thus you'll still have the old version there. Just uninstall the app or reset the simulator if you're trying to address this for testing purposes.
Longer term, the app itself needs some logic that looks up the version number of the database (I create a "configuration" table with this information) in the Documents folder, compares that to what version the app expected to find, and if different, upgrade the database in the Documents folder.
Bottom line, it's useful to check all three databases (project directory, bundle, and app's Documents folder) to see at which step you lost your database changes.

Related

How to move SQLite DB in swift between projects?

I have created a SQLite DB in a project and populated it (in the simulator) with information that I need in another project as well.
Now, I have created another project in Xcode and I want to use my existing DB in that project as well (with the info that is already in the DB of course).
Is this possible? And how?
Short desc.: DB is created in an app in simulator and filled with data in that app.
I want to use the same DB with filled data in a new app that I am programming.
All you need to do is copy the generated database file from the simulator's sandbox to your new project.
To find the file, add a print statement to your project that prints the path to the database file. Then you'll where it is on your computer.

How can I move an existing Core Data xcdatamodeld and sqlite to new project?

I have an existing project we'll call ABC.
I have a new project we'll call XYZ.
All I'm trying to do is copy the MyDataModel.xcdatamodeld from the ABC project folder into the XYZ project folder, and copy the associated populated MyDatabase.sqlite file from the simulator on project ABC into the simulator on project XYZ.
This does NOT work.
I get the error "The model used to open the store is incompatible with the one used to create the store"
I've tried resetting simulator, deleting all apps from simulator, running CLEAN in XCode, and still doesn't work.
When I run XYZ, it WILL create a new EMPTY sqlite database, but it will NOT accept my populated one that is associated with the ABC project and which works fine in ABC.
I need to be able to use my populated one.
The error message tells the tale. You have changed the xcdatamodeld between the time you wrote MyDatabase.sqlite and now. Core Data needs the original xcdatamodeld (unchanged) to be able to read your datafile. Retrieve it from your version control system or from Time Machine and you'll be good to go, although you might have to handle model migration.

Fix Core Data Fail

I have an app in the app store that uses Core Data and I have to release an update by tomorrow. However, I am experiencing some problems with Core Data.I by mistake made changes to my model in Core Data and now my app is crashing. I tried migrating the data but the app still crashes when I updated it on my iPhone. Is there anyway to fix it?
Thank you so much for your help!
EDIT: I am trying to add the .mom file to the app but I can not get it into the Bundle:
EDIT 2: Do I delete the entirely Planner.xcdatamodeld:
You can recover the original Core Data model from the production app's bundle.
Use Finder to open the app bundle (Show Package Contents) and look for a .mom file or a .momd directory.
Copy the file or directory to some location outside the bundle.
Create a new XCode project with Core Data.
In XCode select the newly created projects Core Data model.
Go to the XCode Editor -> Import menu and select the .mom file you have just copied, if need be find the correct version in the .momd directory.
You should now have the model in XCode, save and copy the model file to you original project...
In XCode delete the incorrect model from your project (remember to save a copy first so you have a copy of the new changes)
Use the XCode Add File to... menu to add the old model to the original project
Now compile and run the app to confirm it opens the old file correctly
Now add a new model version and add the changes to this new version - make sure you select the new model version in XCode before making changes
You should revert your model to the one that you have in App Store. Then you should Add new model version of your Core Data model. If you can't revert to that model you should try to make it exactly as it was.
After you've done a new model version, you should select that one and make the changes.
If you don't use Git (which is really, really bad, by the way), you can just install your app from the App Store and use some iPhone File Manager to get the old mom file from your app. It would be in /apps/yorapp/youapp.app/ folder with .mom extension
Try iExplorer, for example, it's free.

Sqlite file deletes on reset of simulator

I am using sqlite in my IOS project. I am copying the sqlite file from my main bundle to documents directory on launch of the application. It does copy, but suppose if I reset the simulator, the sqlite file from documents directory is also getting deleted, thus all the changes made goes away with it.
Any help would be appreciated.
First, you can readup here on where to save persistent data, and how to prevent iCloud backups. In your case of the simulator, you need to add code to your program wrapped in an 'ifdef SIMULATOR' (I don't have a reference handy on what define to test against, but I know there is one), and save a copy of your file to a fully qualified path that leads to your user account (ie /Users/xyz/iOS/xzy.data). When your app starts up, you first look for the file in the appropriate place as you would on the device. Then, if the file is not found, for the Simulator only, you see if there is a file in that hard coded path, and if so copy it back to the Simulator.

What is the definition of a single bundle application in XCode?

I get this error when I try to validate my iPad app archive that I have build with XCode 4:
“TVGuidePlusHD” does not contain a single–bundle application or
contains multiple products. Please select another archive, or adjust
your scheme to create a single–bundle application.
I know about the "Skip install" setting, but still it fails for me.
The contents of the archive are these:
So is the problem the tvguide.db file? This is my .sql document which is compiled automatically to a sqlite db file and actually is supposed to be copied to the application bundle only.
I'll answer my own question.
After making sure that the tvguide.db file is not inside the "Applications" folder, then the archive is considered a single-bundle application and is validated correctly.

Resources