Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIBezierPath persistence with core data

I am working on an application where the user is able to draw on the screen with their finger. I am using UIBezierPath for this. I need to persist this data which is an NSArray containing multiple BezierPath objects. What is the best way to go about this? Store in coredata, store in a file using NSData? Much obliged.

like image 506
Mc.Stever Avatar asked Jul 12 '12 13:07

Mc.Stever


People also ask

What is persistence in Core Data?

Object graph management: Core Data works with defined objects, and core data keeps track of these objects and their relationships with each other. Persistence: Data can be retrieved, in this case, either from the device or from a network location. SQLite: One of the potential data stores that Core Data can use.

What is Core Data in iOS?

Core Data is a framework that you use to manage the model layer objects in your application. It provides generalized and automated solutions to common tasks associated with object life cycle and object graph management, including persistence.

What is a Core Data stack?

As I mentioned earlier, the Core Data stack is the heart of Core Data. It's a collection of objects that make Core Data tick. The key objects of the stack are the managed object model, the persistent store coordinator, and one or more managed object contexts.


1 Answers

Are you expecting to have to store multiple objects? Will you need to be able to fetch them based on some filter or ordering? I recommend using Core Data to save yourself a decent amount of work in packing/unpacking the data. There isn't really a reason to store it in a file.

edit:

As the other answer said, you just archive it to NSData. The UIBezierPath class adheres to the NSCoding protocol so you can do something like this to archive it:

NSData *bezierData = [NSKeyedArchiver archivedDataWithRootObject:bezierPath];

You can persist that NSData object in Core Data.

To decode the archive, assuming we have a bezierData NSData object, you can do something like:

UIBezierPath *bezierPath = [NSKeyedUnarchiver unarchiveObjectWithData:bezierData];
like image 88
Dima Avatar answered Sep 18 '22 07:09

Dima