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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:14:15+00:00 2026-06-04T09:14:15+00:00

I’m working in Objective-C and coming across a consistent problem in my program. I

  • 0

I’m working in Objective-C and coming across a consistent problem in my program. I have a bunch of NSTableViews, and up until this point, I’ve always had to “reload” the data constantly in my two functions : numberOfRowsInTableView and the one that fills them with content.

For example, my “loadData()” function fills an array that’s declared in my .h file with a fetch request (using Core Data).

I would like to only need to access this loadData() function in my “awakeFromNib” function, or whenever things are updated. However I find that the program crashes if I don’t add a call to the function at the top of the two necessary NSTableView functions.

This is starting to cause problems, as I believe it is quite redundant to be constantly fetching from the Core Data file when nothing is changing.

Here is some code:

- (int)numberOfRowsInTableView:(NSTableView *)aTableView {
[self loadData];

if ([aTableView isEqual:(invoicesListTable)])
{
    return (int)[fetchedInvoices count];
}}

If I do not include the [self loadData] function, the program crashes. This happens even if I have [self loadData] in the awakeFromNib function.

Why isn’t my program “remembering” the values of my fetchedInvoices array? It is declared in my .h file as follows: NSArray *fetchedInvoices;

My “loadData” function is as follows:

- (void)loadData {
NSError *error = nil;


// fetch all invoices
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Invoice"
                                          inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc]
                                    initWithKey:@"InvoiceNumber" ascending:YES];
[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];
[sortDescriptor release];


fetchedInvoices = [managedObjectContext executeFetchRequest:fetchRequest error:&error];


if (fetchedInvoices == nil) {
    NSLog(@"ERROR");
}
[fetchRequest release];
// end of invoice fetch

Any help would be appreciated.

  • 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-04T09:14:17+00:00Added an answer on June 4, 2026 at 9:14 am

    Since you are not using ARC – I see calls to -release in your code – you have to make sure that objects stick around for as long as you want them.

    In particular, the -executeFetchRequest:error: returns an array that you don’t own. It has an unpredictable lifetime. Since you are keeping it for an extended period, you need to retain it. If you retain it, then you, of course, have the responsibility to release it when you no longer need it, too.

    The best way to make sure you get memory management right (short of using ARC) is to confine it to -init, -dealloc, and the setters of your properties. So, you should implement or @synthesize a setter for fetchedInvoices with the proper ownership semantics (strong, retain, or copy) and use that to set the property, rather than directly assigning the instance variable.

    So, for example, you might put the following in your class’s @interface:

    @property (copy) NSArray *fetchedInvoices;
    

    and then, in your @implementation, you’d have either:

    @synthesize fetchedInvoices;
    

    or you would implement the setter with the semantics required by its declaration.

    Then, instead of this line:

    fetchedInvoices = [managedObjectContext executeFetchRequest:fetchRequest error:&error];
    

    you would do this:

    self.fetchedInvoices = [managedObjectContext executeFetchRequest:fetchRequest error:&error];
    

    or, equivalently, this:

    [self setFetchedInvoices:[managedObjectContext executeFetchRequest:fetchRequest error:&error]];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am currently running into a problem where an element is coming back from
I am trying to loop through a bunch of documents I have to put
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
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.