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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:23:57+00:00 2026-06-15T04:23:57+00:00

I have a problem with a @sum binding of a column in my program:

  • 0

I have a problem with a @sum binding of a column in my program:

I’m doing a Coredata, NSPersistentDocument based program. I’m doing mostly everything from IB, the creation of the data model, NSArrayController and NSTableView…

I have just 1 entity with 62 attributes (61 NSString and 1 NSNumber). I import a CSV file with 12722 records. Import works well, can save to xml, binary, sqlite… I’ve double checked that the overall process works perfect. Can save/load. Everything is there.

The problem that I have: I’ve created a label that I BIND to @sum of the column with the NSNumber property. This is how I did

>     label->Bindings Inspector->Value
>      Bind to: My_Entity_NSArrayController
>       Controller Key: selection
>       Model Key Path: @sum.myNumericAttribute

When I run the program, click on Import, Select ALL the rows, the @sum works well. It’s fast, however and here is the first problem: once I save the file (tried all… binary/xml/sqlite) and later load it and try to Select ALL again, the program crash without error.

Tried through “Profile”->Allocations. I noticed:

  • I don’t have memory leaks
  • When loading from disk and then select all: Goes extremelly slow. After 5 minutes didn’t yet finished (I stopped it) and I saw +45MB of CFNumber (Live Bytes) and >1.500.00#Overall. So, something is wrong here, as I’m talking about 12722 rows/registers of type Interger32.

The second problem is the same but reproduced from a different angle. Instead of using “selection” I’ve tried to use “arrangedObjects”.
In this case the problem appears even while importing from CSV, it goes extremely slow and it finally crash. Trying to open an already created file also crash.

This is how I did label->Bindings Inspector->Value

>    label->Bindings Inspector->Value
>      Bind to: My_Entity_NSArrayController
>       Controller Key: arrangedObjects
>       Model Key Path: @sum.myNumericAttribute

Can you please help me with some light on what to look for or ideas that can help me find where the problem is?.

Thanks a lot.

Luis


—- NEW EDIT AFTER MORE RESEARCH —-

I’ve found a workaround which I DONT’ UNDERSTAND, please comments/answers really appreciated.

My program uses Coredata (SQLite), NSPersistentDocument, NSTableView and an NSArrayController. I want to have a working NSTextField bound to a @sum Collection Operation

Problem: As soon as I open an existing document with SQLite DB populated and I try to bind to the arrangedObjects.@sum.t_24_Bookings from the NSWindowController, the program crash.

My initial guess it’s related to the Cannot access contents of an object controller after a nib is loaded however I’ve followed the recommendation of performing a first Fetch like this without success:

- (void) awakeFromNib
{
    :
    BOOL ok = [[self out_CtEn_Transaction] fetchWithRequest:nil merge:NO error:&error];
    :

Continuing with this idea I’ve found that if I create a “real” complete Fetch + I perform a @sum access from the Document subclass, then it works.

Here is the code with comments I’ve put in place in order to have the workaround working.

ABDocument interface (a NSPersistentDocument subclass)

@interface ABDocument : NSPersistentDocument {

    BOOL        ivNewDocument;
    NSArray     *ivFetchedTransactions;
    NSNumber    *ivTotalBookings;
}

@property (nonatomic, getter=isNewDocument) BOOL newDocument;
@property (nonatomic, retain) NSArray   *fetchedTransactions;
@property (nonatomic, retain) NSNumber  *totalBookings;

:

ABDocument implementation

#import "ABDocument.h"
#import "ABWindowController.h"

@implementation ABDocument

@synthesize newDocument                 = ivNewDocument;
@synthesize totalBookings               = ivTotalBookings;
@synthesize fetchedTransactions         = ivFetchedTransactions;

:

/** @brief Create one instance of my custom NSWindowController subclass (ABWindowController)
 *
 * In my NSPersistentDocument I do override makeWindowControllers, where I create 
 * one instance of my custom NSWindowController subclass and use addWindowController: 
 * to add it to the document. 
 *
 */
- (void) makeWindowControllers
{
    // Existing Document?
    if ( ![self isNewDocument]) {
        // NSLog(@"%@:%@ OPENING EXISTING DOCUMENT", [self class], NSStringFromSelector(_cmd));

        // Opening existing document (also has an existing DDBB (SQLite)), so
        // make sure I do perform a first complete "fetch + @sum" to void issues
        // with my NIB bind's.
        [self firstFetchPreventsProblems];
    }

    // Now I can create the Window Controller using my "MainWindow.xib".
    ABWindowController *windowController = [[ABWindowController alloc] init];
    [self addWindowController:windowController];
    [windowController release];    
}


/** @brief First complete "fetch + @sum" to void issues with my NIB bind's.
 *
 *  Before I create the Window Controller with "MainWindow.xib" I have to perform a
 *  first Fetch AND also retrieve a @sum of an NSNumber column.
 *
 *  My NIB has an NSTextField BOUND to @arrangedObjects.@sum.<property> through a NSArrayController
 *  If I don't call this method before the NIB is loaded, then the program will crash.
 *
 */
- (void) firstFetchPreventsProblems {

    // Prepare the Fetch
    NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Transaction"];

    // 1) Perform the Fetch
    NSError *error = nil;
    [self setFetchedTransactions:[[self managedObjectContext ] executeFetchRequest:request error:&error]];
    if ([self fetchedTransactions] == nil)
    {
        NSLog(@"Error while fetching\n%@",
              ([error localizedDescription] != nil) ? [error localizedDescription] : @"Unknown Error");
        exit(1);
    }

    // 2) Execute Collection Operation @sum
    [self setTotalBookings:[[self fetchedTransactions] valueForKeyPath:@"@sum.t_24_Bookings"]];
}

ABWindowController (The controller that loads my NIB)

- (void)windowDidLoad
{

:
        // PROGRAM CRASH HERE 
        // IF [self firstFetchToPreventsProblems]; is NOT CALLED
        // ABDocument's "makeWindowControllers:"
       [[self totalSumField] bind: @"value" toObject: [self out_CtEn_Transaction]
                       withKeyPath:@"arrangedObjects.@sum.t_24_Bookings" options:nil];

}

Please If you can comment really appreciated, I’ve got a solution but I don’t understand why.

Tanks,
Luis

  • 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-06-15T04:23:58+00:00Added an answer on June 15, 2026 at 4:23 am

    I found the problem myself after several days researching. It was easy (now that I know):

    In parallel I was creating a secondary thread and happened that I was accessing the data model from two different threads. As it’s been explained in several Q&As here in Stackoverflow, it’s very dangerous.

    I’ve applied the commented solutions in several posts of creating a secondary MOC in the secondary thread.

    Now my code is thread safe as per coredata related actions, so program is not crashing.

    Thanks again to the community.

    Luis

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

Sidebar

Related Questions

I met a problem with sum function: the data have a datetime column and
I have problem about program to find the sum of 10 numbers in an
I have a problem with the following HQL query: select sum(MYTABLE.COUNTER) from ( select
i have problem in data binding in expandable list view. here i use ArrayList<ExpandListGroup>
I have a problem with this query trying to get a sum and a
I have a problem with an SQL query. SELECT SUM(table_colum) AS value, SUM(value *
I have problem with UIWebView delay when the load image from url. In my
I have problem while loading data into html select when users press or click
I have problem SIMILAR to preventing form data reposting, but not quite the same
I have a problem with a MySQL statement: select sum(x) as sum, 01.06.2010 as

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.