How do I update data in magical records - iphone

I am using core data in my swift project and I am using magical record for core data I want to edit already saved data.
I am fetching editing task like this:
array = Tasks.MR_findByAttribute("task_name", withValue: entryLabel.text)
I am getting data which I want to edit. I am not understanding how to edit this and save in the place of old record. Can anyone please tell me the syntax.

In MagicalRecord, you modify data the same way you would with plain Core Data:
fetch
change attributes / relationships
save
The most commonly used API in MagicalRecord for this is the class method saveWithBlock. In the block you fetch your entities and modify them.

Related

Loading plist into core data

I have the code to actually load the data from my plist into the entity in core data. But where I seem to be stumbling finding any latest posts or info is how to check to see if that entity already contains the data/time to load the data into core data. I can only seem to find outdated non swift fetchrequests to check I don't read anything non swift so I have no idea how to sequence them in swift language....If you need to look at the code I have to actually load the data I can provide it. I know how to read the plist but as far as actually loading the plist to core data is where I am needing the help.
let databaseAlreadyCreated = NSUserDefaults.standardUserDefaults().boolForKey("databaseAlreadyCreated")
if !databaseAlreadyCreated {
//call your function to setup your core data database
NSUserDefaults.standardUserDefaults().setBool(true, forKey:"databaseAlreadyCreated")
NSUserDefaults.standardUserDefaults().synchronize()
}
That's the simplest approach. You can also create another entity for your Core Data which will store applications settings.
Finally, you can try to fetch your entity and if it exists - it means you have already created it. If the results count is 0 - it means that you have to set it up.

Sort core data using sort descriptors using variable held outside of core data

My Question...
Is it possible to sort data using the sort descriptors in a fetchedResultsController by data that isnt stored in core data?
My situation...
I have a core data stack which includes a entity called 'Client'. One attribute of Client is addressBookID which contains the unique address book ID. I don't want to store names in my stack to avoid issues when names are updated etc...
Is it possible to fetch the results from core data, using the addressBookID get the names of the people and then sort them according to last name?
Ben,
Core Data fetch requests return an array of objects. As such, you can sort a mutable copy of it based upon any criteria you dream up. Hence, the answer to your question is yes.
Andrew

Save MKOverlay to Core Data

I have an application that tracks a user and shows where they've been using MKOverlay. How can I save this information into Core Data so that when the user wants to see where they went yesterday they can load the map/overlay from Core Data?
I have a similar project. Mine is for cycle paths. Here is how I structure my core data model:
I use an order parameter so I can work out how the points connect up. But i think you can just check the 'ordered' property of the relationship now although im not entirely sure how it works. The min / max attributes are for more efficient searches. I store the lat long values as integers to save space after a suggestion to one of my posts. You might find this useful too.
You probably want to add some attributes to the Way such as Date.
You can save any object in a core data model, but if they are not the default type like string, int, etc. you won't be able to query on them.
So you have to construct your entity with property that you will be able to query.
So I see 2 options, you save every information in an entity, but this way you will need to alloc again all objects.
Or you only save the property you will need to query and archive your object in a transformable or in a Binary Data property.
I don't know what would be best.

is it possible to use more than one SQLite files in CoreData?

Hello fellow stackoverflow family members?
I know it is un-efficient to create one extra sqlite table in iPhone CoreData system. (X)
Currently, My app has one sqlite table but there are preset data to users to no need to waste parse time. But if I adding new entity in current structure of SQLite table, it wipes up the whole preset data. I haven't tried to use immigrate method but I don't think it wouldn't be just adding a new entity on the table. I'm thinking it also wipes up previous preset data.
Current Architecture of SQLite file.
entity : A
attributes : contains data
I want to keep A with attributes still contain data but also add new entity : B.
entity : A
attributes : previous contained data
(PLUS+)
entity : B
attributes : new data
Do I need to create extra persistence set to separately store entity B (create another SQLite file and use as storage) or Is there possible way to add entity B in current SQLite with no changes in entity A?
Thank you.
To directly answer your question: Yes, you can reference multiple SQLite files in Core Data. You'll want to use a unique persistent store for each one.
I don't understand the rest of your question though, so it may be likely that creating multiple persistent stores is not what you want at all.
I know it is in efficient to create one extra sqlite table in iPhone CoreData system.
This is untrue. Creating multiple entities (aka, tables, but that is abstracted away) can lead to much more efficient queries.
Currently, My app has one sqlite table but there is no need to change preset sqlite table but want to add some other attribute.
Just add the attribute to your entity. If your app has already been released or you want to maintain existing data, you'll have to set up a migration and/or turn on lightweight migration.
So commit with new attribute and update coredata is not valid. Because it flash off current data set and need to spend another hours to type manually.
This didn't make any sense to me. Can you clarify?

iPhoneOS Core Data migration: moving something from an entity into a file

I have a scenario where I'm moving the contents of a blob stored in a core data entity into a file. I need a way to export that data during a migration, where I know the entity that's being converted and save the blob to a file, writing the location of that file into the converted entity's appropriate attribute.
I can't seem to find a way to do this. The docs regarding the Three Stage Migration seem to indicate what can be done, but I'm not sure where to define things, or what exactly to define.
You can do this by creating a mapping model and then creating a custom NSEntityMigrationPolicy for that entity. From there you can do the modifications to your data structure as needed.