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 3965798
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:30:48+00:00 2026-05-20T03:30:48+00:00

I’ve added the following image to help illustrate the problem better: Hi, I’m looking

  • 0

I’ve added the following image to help illustrate the problem better:

image of window

Hi,

I’m looking for the best starting point to alter the data stored my core data model directly – speaking as someone who’s new to the area. From my reading I’m pretty confident I shouldn’t touch my NSArrayController, which was my natural instinct, and that I should always tackle the model. This makes sense but because I’ve used bindings and core data, xcode has generated everything for me and I don’t have a sense of building up a class from scratch myself.

For my initial task, I have a ‘jobs’ entity and NSArrayController. It has a jobTotalHours attribute that’s a string in the 00:00:00 format and has a corresponding ‘Hours’ column for each job in an NSTableView. Separate to this, I have a stopwatch button that’s linked to a text field next to it, displaying time as a 00:00:00 string. I have a class working that starts and stops a timer counting and displays it in increments of hours, minutes and seconds.

What I need to do is to make the timer add time onto the jobTotalHours attribute for the current job highlighted in the NSTableView. The separate textfield has now been bound to display the time of the current highlighted hours column so that part’s taken care of. In other words, the timer was originally adding time to a test variable and displaying it in an autonomous text field for testing reasons. Now I need it to add time onto whatever job is highlighted in a table view and I need to access the model programmatically without being sure of what step to take first.

Thanks in advance for any advice. I’ll include the timer class below if it’s any use. I’m pretty sure it’s rough and bad but it works:

timerController.h:

#import <Cocoa/Cocoa.h>
BOOL timerStarted;
int timerCount;
int timerSeconds;
int timerMinutes;
int timerHours;
NSString *timerString;
NSString *timerFieldSeconds;
NSString *timerFieldMinutes;
NSString *timerFieldHours;

@interface timerController : NSObject <NSApplicationDelegate> {
    NSWindow *window;
    NSTimer *timerNoOne;
    IBOutlet NSCell *timerOneOutputLabel;
    IBOutlet id timerClockField;
}
-(IBAction)toggleTimerClock:(id)sender;
@property (assign) IBOutlet NSWindow *window;

@end

timerController.m:

#import "timerController.h"


@implementation timerController
-(IBAction)toggleTimerClock:(id)sender
{
    if (timerStarted==FALSE) {
        timerStarted = TRUE;
    } else {
        timerStarted = FALSE;
    }
}

@synthesize window;


- (void) awakeFromNib {
    // clear timer 
    [timerClockField setStringValue:@"00:00:00"];
    // initialize timer to count each second
    timerNoOne = [NSTimer scheduledTimerWithTimeInterval:1 
                            target:self 
                            selector:@selector(updateTimerNoOne:) 
                            userInfo:nil 
                            repeats:YES];   

}


- (void) updateTimerNoOne:(NSTimer *) timer {
    if (timerStarted==FALSE) {
        // do nothing. Timer is switched off.
    } else {
        timerCount = timerCount + 1;
        timerSeconds = fmod(timerCount, 60);
        timerMinutes = floor(timerCount / 60);
        timerHours = floor(timerCount / 3600);

        if (timerSeconds < 10) { // add a leading 0 for formatting reasons.
            timerFieldSeconds = [NSString stringWithFormat:@"0%d",timerSeconds];
        } else {
            timerFieldSeconds = [NSString stringWithFormat:@"%d",timerSeconds];
        }

        if (timerMinutes < 10) {
            timerFieldMinutes = [NSString stringWithFormat:@"0%d",timerMinutes];
        } else {
            timerFieldMinutes = [NSString stringWithFormat:@"%d",timerMinutes];
        }

        if (timerHours < 10) {
            timerFieldHours = [NSString stringWithFormat:@"0%d",timerHours];
        } else {
            timerFieldHours = [NSString stringWithFormat:@"%d",timerHours];
        }

        NSString *timerString = [NSString stringWithFormat:@"%@:%@:%@",timerFieldHours,timerFieldMinutes,timerFieldSeconds];
        //[timerClockField setStringValue:timerString];

    }
}
@end

Update:

From reading some more, I’m wondering if it’s a better approach for me to update the string in the textcell itself on each second of timer change and then only commit changes to the model on the timer finishing (e.g. the clock was stopped). Previously I was thinking of saving the model’s jobTotalHours string second by second as this was directly altering the model and avoiding controllers, which I thought was the advised route to take.

Update:

I had a subclass set up for NSTableView and NSArrayController. I was able to use them to detect selection changes to the rows in the table and print them out to the console. The subclass was called:

@interface modelUtilController : NSObject

Which performed the above tasks fine. I now wanted an outlet to the NSManagedObject so that I could directly manipulate assets in it while keeping outlets to the NSTableView to detect changed in row selection. I read that the subclass should be

@interface modelUtilController : NSManagedObject

which I changed it to and included an outlet to the data model. This crashes the original detection for changes in row selection, so I’m doing something wrong now. Perhaps I have to separate the subclass into 2?

Update : Possibly Complete

Ok I think I’ve solved this after 3 days at it. As far as I can see it’s working but I haven’t put it fully to work yet. Basically I created a separate function that I call from my timer once every second:

void amendTotalHours(id anObject)

This function uses my jobs NSArrayController and then finds the current value in the hours column using:

NSArray *selectedObjectsArray = [anObject selectedObjects];
NSManagedObjectModel *firstSelectedObject = [selectedObjectsArray objectAtIndex:0];
NSString *readCurrentTime = [firstSelectedObject valueForKey:@"jobTotalHours"];

I then convert the string of time formatted into 00:00:00 to an integer of the total seconds. I add one onto this for each call from the timer and then convert the seconds back into a string in the 00:00:00 format. Finally, I send this back to the NSArrayController using:

[firstSelectedObject setValue:[NSString stringWithFormat:@"%@", timeValue] forKey:@"jobTotalHours"];

And cry a (maybe temporary) sigh of relief.

  • 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-20T03:30:49+00:00Added an answer on May 20, 2026 at 3:30 am

    Ok I think I’ve solved this after 3 days at it. As far as I can see it’s working but I haven’t put it fully to work yet. Basically I created a separate function that I call from my timer once every second:

    void amendTotalHours(id anObject)
    

    This function uses my jobs NSArrayController and then finds the current value in the hours column using:

    NSArray *selectedObjectsArray = [anObject selectedObjects];
    NSManagedObjectModel *firstSelectedObject = [selectedObjectsArray objectAtIndex:0];
    NSString *readCurrentTime = [firstSelectedObject valueForKey:@"jobTotalHours"];
    

    I then convert the string of time formatted into 00:00:00 to an integer of the total seconds. I add one onto this for each call from the timer and then convert the seconds back into a string in the 00:00:00 format. Finally, I send this back to the NSArrayController using:

    [firstSelectedObject setValue:[NSString stringWithFormat:@"%@", timeValue] forKey:@"jobTotalHours"];
    

    And cry a (maybe temporary) sigh of relief.

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

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
I want to construct a data frame in an Rcpp function, but when I
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have some data like this: 1 2 3 4 5 9 2 6

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.