retrospct
retrospct

Reputation: 161

What is the best way to store data sets for graphing in Core Data?

I am having trouble grasping what the best implementation of this functionality. My end goal is to take stats from a note document such as word count and line count by session (session being one instance of opening the document and editing it then closing it). Then take that data and graph it over time. I can't find anything related to using core data this way. I'm using a NSFetchedResultsController in line with the awesome iOS lectures posted by Stanford.

This could simply be a huge misinterpretation of core data on my part. Would it be easier to save each session data as NSString attributes in a similar format to "timestamp - wordCount" and "timestamp - lineCount" for later parsing?

I have an app which has a text documnt lets call them "notes" entities. Each note entity has a "stats" entity associated with it in a one-to-one relationship. The notes entities keep individual total wordCount and lineCount attributes while the stats entity keeps data attributes in data sets in the NSString format mentioned above.

The reasoning is that I want to be able to launch the notes objects on start without having to load a ton of data on app launch.

Is this the best way to keep this sort of data? Just seems kind of jenky to me for a lack of better words. I read the apple documentation on Core Data, watched some tutorials including the Stanford lectures and searched this up through Google-fu skills but couldn't find anything. This is my first time using Core Data so I believe I'm just having a hard time actually applying what I've learned.

If I missed anything please feel free to call me out as I was writing this while walking. Thanks in advance.

Upvotes: 0

Views: 108

Answers (1)

FluffulousChimp
FluffulousChimp

Reputation: 9185

Attempting to capture a couple embedded questions:

Would it be easier to save each session data as NSString attributes in a similar format to "timestamp - wordCount" and "timestamp - lineCount" for later parsing?

Easier, possibly? But NSString is not a good way of storing elemental data.

Is this the best way to keep this sort of data?

You're referring to packing metadata about the documents into an NSString; I'm sure it would work - but probably better to encapsulate the metadata in a class of its own - or alternatively as you suggested Core Data.

My suggestion is the former; that is, I would take the data that you are packing into a NSString and make a class out of it. The Apple documentation outright states that Core Data is not an entry-level technology. It's often a good solution for the implementation of your model layer; but not always. In your case, you could do something as simple as:

@interface NoteMetadata:NSObject

@property (nonatomic, assign) NSInteger wordCount;
@property (nonatomic, assign) NSInteger lineCount;
@property (nonatomic, strong) NSDate *timeStamp;

@end

etc., then perhaps your Note object could have an array of these NoteMetadata objects that comprise the sessions.

Upvotes: 1

Related Questions