I will start developing a new project for iOS. I am unsure for now if I should use core data in this project, or not. I will find out along the way, while developing (most likely with some coaching help).
Now my noob question is: Should I, while creating my new project, already check the option 'use core data'? Or shouldnt I?
Basically my question is: What is more difficult, removing core data when I checked the option and I will not been using it after all? Or adding core data when I did not check the option and I will be using it after all?
I have found it is not super difficult to add after:Implement CoreData into an existing project using Swift
But still, it seems like alot of hassle, so I now ask u!
Thanks for the answer in advance
It doesn't matter. Starting with Core Data just prepares the core data code in the app delegate and makes an empty model file, both of which are
1) easy to create yourself, or
2) copy from a new empty project started with core data later when you need it.
And if you already have it in your project, but you don't use it, it is also no problem. I found that almost all projects need core data after a while, so I usually just let it create it from the start.
Xcode just allows you to check using coredata to prepare already a coredata for you project.
BUt it is very simple to add or remove it later.JUst simple as File>create or File delete.
In a words don't worry about creating in the begining or later.
Related
I want to bundle read-only realm database with my app. I was able to do this by following this tutorial. There are couple of issues with this solution though. The fact that I had to create another xcode project for it comes with various cons like:
I have to keep duplicates of my classes inheriting from Realm Object and manually keep them in sync between two projects
I have to open another project each time I want to create new updated realm database
It would be weird to keep 2 xcode projects in one git repository
My question is: Is it possible to add some kind of standalone script to my project that would have access to my realm objects and realm library that I could manually run from time to time instead of having to do that in another project?
I was looking into adding playground and running it from there, but I think that swift package manager is currently bugged in a way that doesn't allow to build such a solution as I'm getting This will result in duplication of library code. error that cannot be fixed with DISABLE_DIAMOND_PROBLEM_DIAGNOSTIC flag.
Is there some other solution than having to do it within another project? I think there must be a way to run utility scripts like this - that aren't strictly part of the app, but surprisingly I couldn't find any so far.
it's been a while I'm working on a project and I just discovered that I have to use the Core Data framework.
The issue is that I did'nt tick the Use Core Data case when I created the project and I don't know what I have to modify to make it work.
I think this is mostly in the AppDelegate but I'm not sure.
Thank you very much guys.
Elbattore
My question is fairly simple though I couslnt find anything specifically answering it till yet.
I have an obj-c app that I'm updating fairly often. I would like to create a new swift app with the same bundle id to replace the older one as an update. I have like 8 core data model versions within my old app that I would love to migrate to the new swift-from-scratch-app, so my users wont lose their data. Is it even possible??
Thank u
If you're using the exact same bundle ID (this is key), then from the perspective of iOS, it is considered exactly the same app. Consider your users having version 1.x of your app installed on their devices and you release 2.x using your new Swift project. Your user, nor iOS, will be able to tell this is a brand new app written in Swift.
The gotcha here is that unless you use the exact same model names, CoreData won't be able to be initialized with existing data and you'll be forced to write a custom migration for this.
My suggestion to you is to copy the xcdatamodel file from your old project and change the language of the code it generates once copied into the new project.
Then regenerate your entities in Swift and continue working like nothing ever happened.
I've created a mess around To Do list app in Tabbed Application, Xcode 6 beta. Currently giving this a go in swift.
How do I go about getting the core data added into the app delegate file? When I go to create a new tabbed application there is no option to get it added. I notice you can turn core data on in other project templates but not this one?
The easiest way to do so is just creating a new application with Core Data enabled, copy and paste the code from AppDelegate.swift and create a new Core Data Model (Cmd + N > iOS - Core Data > Data Model). The only thing you have to do is replace the database name from your demo project with the name you chose for the Core Data Model you created. To do so, just search for your old project name in the code you pasted and replace it with the name of your new Core Data Model.
I also tested what you said and the missing Core Data checkbox for tabbed applications should be an Xcode 6 bug but it does not really matter which template you choose for the application. The Core Data code is the same across all the templates, the only difference between these options is the interface that is generated by Xcode.
Have a look at the framework in the Apple Developer Documentation - Core Data > Topics > First Steps. It’s excellent and you can copy and paste the code. Here’s the link:
https://developer.apple.com/documentation/coredata
I created one project with core data that will work with unchangeable database. And I don't want to write code in this project , that will programmatically populate this database. So, I create second project with core data, add existing xcdatamodel from first project without copying(only references). There i populate my database, open it with mozilla plug-in and it successfully filled. Then I copy ,my *.sqlite file and manually replace it with old file in first project. It causes error:"The model used to open the store is incompatible with the one used to create the store". But I use for both files the same xcdatamodelid. Where my error?
Sorry for my english, I really need help.
P.S. when I open sqlite file from first project and second (with commented code of populate base) in FileMerge - second is already empty. I appreciate any advice or help.
Karoly S nicely answers the question. I have a hint that I frequently employ that may prevent this out of sync situation. Instead of two Xcode projects trying to share one model file, just create one Xcode project with two targets. Each target will use the same model file, any class definitions derived from that model, and possibly other code. My second target is a Mac OS command line program that generates the database, while my first target continues to be the iOS app that reads that database. The Mac OS target will overwrite the database file in a project subdirectory, ensuring it's up-to-date. If I make any changes to the model, Xcode knows to update both targets.
Did you change your Model Definitions in any way? The error you are seeing is because there is some difference between the model from when you created it, and again from when you are trying to reference it. Are you running on the simulator? Try to delete both of your apps to clear the data related to it, as it might be out of date. Afterwards simply rebuild both of your projects as that will update your core data database.
EDIT: To clarify a bit more, your core data model is out of sync, this is generally caused by you building and running an app, and a database being created, then redefining your object model, this can be done in a variety of ways, most likely caused by the addition of an attribute or entity. So when you are trying to load the database there are fields that the app and core data are looking for, but are not there because they did not exist when the database was created. I hope this helps.