Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7079107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:37:50+00:00 2026-05-28T06:37:50+00:00

I want to create an application that logs when I have gone jogging and

  • 0

I want to create an application that logs when I have gone jogging and uses Core Data to store the information. I want to store each workout with the date, distance and time I have run. I also want to be able to display a Summary which contains the total amount of times I have gone to run and the total distance run.

In my disign, I could display the summary directly from the Workout objects. How many times I have run is just the amount of workout objects and I could sum up the distance in each Workout to obtain the total distance run. However, I think that the second operation is too costly because I have to scann the whole database every time I want to display that data (This is the same problem as in iTunes you want to display the total amount hours of music you have in your device). I could store this information in a property every time the app lunches, but I guess that would cause a slow start up. Because of that, I thought I rather have 2 coredata objects Summary and Workout:

+---------------------+                    +---------------------+
|Summary              |                    |Workout              |
+---------------------+                    +---------------------+
|totalDistance        | <--------------->> |date                 |
|totalAmountOfWorkouts|                    |distance             |
+---------------------+                    |time                 |
                                           +---------------------+ 

Now here it comes the question. How should Summary be updated?

I could manually update the totalDistance and totalAmountOfWorkouts. I imagine implementing some sort of updateWorkout method which is triggered every time I create a new Workout. However, I know that Coredata has already observation capabilities and could tell me when a new Workout object has been inserted and I could update Summary: KVO. I have never used KVO and I wonder if this is the right case to use KVO? But how do you do that? Is actually KVO the best approach to solve this problem or should I rather implement a protocol in Workout and assign Summary as a delegate? I vagally remember to have heard that the KVO pattern is difficult to debug.

Summarizing, my questions are:

Q1: Should I get totalDistance directly scanning the DB?
Q2: Should I use KVO or the delegate pattern?
Q3: How is totalDistance updated?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:37:51+00:00Added an answer on May 28, 2026 at 6:37 am

    Use the simplest API available. Let’s say you have an array of fetched Workouts. Then simply do

    float distance = [[fetchedObjects valueForKeyPath: @"@sum.distance"] floatValue]
    

    Only if this doesn’t meet your performance requirements, consider KVO or other mechanisms for caching the distance value. Real-time computation is always preferable to caching if the performance is acceptable. But I find it hard to believe that CoreData couldn’t handle the amount of Workouts you could realistically do in a lifetime.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a WinForm application that must draw data coming from a
I want to create a multi-tenant application that uses the hostname to determine the
I want to create an application that will show some predefined message each time
I want to create an application that doesn't use Portrait mode. I am not
I want to create a web application that allows users to sign up, register
I learning Perl and I want to create a simple application that gets all
I want to create an application for Android that will be able to scan
I want to create a remote webservice for an application that is now avaliable
I want to create a c# application with multiple windows that are all transparent
I want to create a navigation application but can't found any icons/symbols that suitable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.