I have done the following to try and answer this question:
I have scanned the Apple documentation on Core Data
I have done this very good tutorial: Core Data from Scratch
I have scanned other articles in an attempt to answer this question
Further detail on my question:
I have an existing iOS application. To achieve persistence, I am currently, by hand, marshaling and unmarshalling JSON files which I store in a directory on the phone. I would like to instead use Core Data in the same kind of way that you might use Hibernate or another ORM tool with my existing domain model.
Which is to say I would like to have something like:
MyDomainObjectDAO
save( myDomainObject )
load( id )
etc. etc.
Where the implementation of those methods involves handing an instance of myDomainObject to something like an ORM context which then stores the object. C'est possible?
I imagine that I could copy all the values from my existing object structure into managed objects created by the core data Apple tools, but I wanted to ask if there was a better way to do this. I would like to keep my convenience methods on my domain objects
If I understand your question correctly you are looking for RestKit. What you will do is create a relationship between your object model and your JSON. You will find that you can almost do it all on the fly without creating any NSObjects manually or parsing any JSON. All you have to do is create the CoreData scheme and create some mapping instances. RestKit will convert your incoming JSON to these objects before persisting them into CoreDate. RestKit is awesome though a bit slow!
Related
In an iOS app, I'd like to take parse the response from an API, serialize it, and then convert it into a form that can be persisted onto disk.
How do I do that without creating duplicate classes?
It looks like there's no direct way to create Mantle objects and then save them into Realm without having two classes for each conceptual entity. You need a MTLModel subclass and a RLMObject subclass.
Ditto for Mantle with Core Data.
swift/objective-c support only single inheritance so a class cannot have more than 1 super class.
if you want to use Realm and Mantle you have to "duplicate" model for each framework
why do you want to use both? each seems to do the same thing just in a different way
I am relatively new to asp.net mvc and Ihave been trying to create a simple CRUD application without using a database and consequently without using DbContext. However, it seems as no feasible. Should I consider DI to address that?
Any ideas would be very welcome.
You will need object persistent framework of some type or can create your own. This can all be done without a database but will use persistent theory.
Really the only way to start doing this is with persistent software programming theory. You would create an object inside an object and inside another object. The objects are stored via an array. You would then need to iterate through the arrays to find the particular item to remove the object from the array.
For example, you would create object of country and then store objects of a state in the country. Then inside of the state array you would store people in another array.
Could create Universe, inside universe would be constellations, and inside constellations would be the star object. All this is stored using arrays.
To save the state you would store all this to a bin file using serializable class that that country array would read to restart the state of all the objects. I have wrote software like this for desktop applications in VB.
I am thinking you would do the same thing using C# and simply create your objects.
Is this the type of thing you had in mind?
This same theory can be used instead of using cookies to track a users progress on a site, but seems like most people just use a cookie.
you could use a static dictionary if you want to do this just for learning purposes,
note you'll loose all the data on app stop,
here's a tutorial for asp.net mvc basics which does a bit of crud at the end without DB: http://youtu.be/fsfOFL4bXXA
I am developing an iOS app and have several object models. Now I want to convert them to core data managed objects, so creating the entities and attributes from the object instead of the standard opposite way of generating the objects from the model. What is the best way to accomplish this?
I tried extending from NSManagedObject instead of NSObject, then manually creating the entities and attributes and setting up the Class name for the entity but that didn't work :-(
Thanks
I recently did this for a big project with a very large and complex data model. Here is a workflow that I found to be very feasible.
First, I create a new data model in Xcode and populate it by hand. This is a very good exercise as it forces you to review your model and perhaps take advantage of simplification opportunities.
Then, generate your class files with Xcode from the model. If you have any special code that should be included in the objects, add them as categories in separate files (e.g. Event.h & Event.m generated by Xcode, Event+Additions.h & Event+Additions.m with your code).
I have an app I am building in iOS, version 5. This app is using a WebAPI built with C# which calls SQL Server stored procedures. The WebAPI uses RESTful calls made to populate items within my iOS app which are returned to my iOS after an authentication challenge in JSON format. All of this works well. As a best practice I am interested in the best approach to consuming and returning data back to the database. Right now I have some custom classes or entities that represent the data returned from my service, for example, I pull all product data based on some category or subcategory and populate an array of type Product. This Product class matches the exact structure of the data returned, i.e. ProductID, ProductDescription, etc. I know this can be duplicated with SQLite and CoreData. What I am wondering is this. Does it make sense to use CoreData, if so, what advantages will I see in using CoreData.
Also, a second part to this question. For arrays of items that rarely change, does it make sense to place those items in pLists? An example of this type of data might be something like Units of Measure where quart, cup, gallon, etc would be listed in a UITableView for the user to select from but it's not likely that the application will need these values updated often if ever.
I would recommend RestKit. From RestKit website:
RestKit can populate Core Data associations for you, allowing natural
property based traversal of your data model. It also provides a nice
API on top of the Core Data primitives that simplifies configuration
and querying use cases.
It seems to meet your requirements.
I would not go for SQLite. It may seem easier but using RestKit with Core Data will give you a lot more.
I am pretty new to using Core Data, so I'd like to ask how I graphically add items to the database I am making. With graphically I mean like in navicat I can edit things with editor.
Core Data is a object oriented framework that provides object persistence, not a visual database editor. Xcode contains a visual tool for creating and editing Core Data models, which are similar to database schemas, but there's no visual facility for managing or manipulating the data that a model describes. It can take a little while to understand Core Data; I'd suggest starting with Apple's Core Data Tutorial for iOS.
May be am not clear with the term graphically. When you start creating your model using Core data, you need to choose a data model from project resources (of type .xcdatamodel) and when you select this,it wil open a model editor for you. you can create as many entities, related attributes and establish relationships. Hope this will help you.
~Manoj.
If you just need to instantiate a new entity and add it to your data store, you'll use the method insertNewObjectForEntityForName on NSEntityDescription to create a new instance of your entity and insert it into your context. You have to call saveChanges on the context to persist that new entity to your data store. Core Data is a really powerful framework, but it isn't something most developers can just start using blindly. Read the Core Data guide, download some of the sample code, and you'll be rocking in no time.