jdross
jdross

Reputation: 1206

Update core data (magical record) with new location data

I have a function that is called every time the location update delegate is called. I'm sure this is not the best way to go about this, since updating this often can be expensive. Could someone point me into the right direction of making the update every 10 seconds or so?

My current code:

TrackCoords *oTR= [TrackCoords MR_createEntity];
oTR.speed=[NSNumber numberWithInt:Location.speed*2.2369362920544];
oTR.lat=[NSNumber numberWithInt:Location.coordinate.latitude];
oTR.lon=[NSNumber numberWithInt:Location.coordinate.longitude];
oTR.elevation=[NSNumber numberWithInt:Location.altitude];

[[NSManagedObjectContext MR_defaultContext] MR_saveToPersistentStoreAndWait];

Upvotes: 1

Views: 86

Answers (1)

Mundi
Mundi

Reputation: 80265

You code looks fine. It is not too frequent as far as Core Data is concerned.

If you are concerned about "expensive", also in the sense of battery drain etc., try reducing the updates sent to the location manager delegate, by observing only significant location change.

Upvotes: 1

Related Questions