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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:43:59+00:00 2026-06-08T08:43:59+00:00

I have added a category to my NSManagedObject IBCompany , which should retrieve a

  • 0

I have added a category to my NSManagedObject IBCompany, which should retrieve a specific time period, which is one of the IBCompany’s relationships, based on a simple date comparison.

When I run the following code, the NSArray sortedFinPeriodsDesc contains the faulted periods in the correct sorted order. However, when accessing them in the for each loop, each of the periods returns nil for its attributes, and in particular, nil for its EndDate. For this reason my method lastReportedPeriodforDate always returns nil, which is an error.

#import "IBCompany+FinstatAccessors.h"

@implementation IBCompany (FinstatAccessors)

NSArray *sortedFinPeriodsDesc;

- (IBFinPeriod*)lastReportedPeriodforDate:(NSDate*)date;
{
    if ( !sortedFinPeriodsDesc ) {
        NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"EndDate" ascending:NO];
        sortedFinPeriodsDesc = [self.finperiod sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];
        }   
    IBFinPeriod *lastPeriod;
    for (IBFinPeriod *finPeriod in sortedFinPeriodsDesc) {
        if ( [finPeriod.EndDate compare:date] == NSOrderedAscending ){ // finPeriod.EndDate < date
            lastPeriod = finPeriod;
            break;
        }
    }
    return lastPeriod;
}

However, when replacing the first lines (lazy instantiation) in the method by removing the if clause and always instantiating and sorting NSArray sortedFinPeriodsDesc, the code works fine.

Hence, I have a couple of questions:

  • What is the error in my code? How does affect lazy instantiation
    faulting?
  • Would you recommend defining the NSArray sortedFinPeriodsDesc as transient attribute and sorting it in awakeFromFetch instead?
  • What would be the best option in your view?

Thank you very much for your help!

  • 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-08T08:44:00+00:00Added an answer on June 8, 2026 at 8:44 am

    The “lazy loading” smacks of a premature optimisation. Particularly the way you’ve implemented it, you aren’t actually using an instance variable, but a global variable (see here for details), meaning that each object isn’t holding its own version of the array.

    I would suggest having the array local and generating it each time it is required. If this impacts performance, you can look at other methods, but even with the ivar problem above resolved, you are going to hit problems if the periods set is updated – your array is now out of date.

    You haven’t said how many times your objects are being asked for this period, or how many objects, or how many periods, so it is difficult to give more specific advice.

    A fetched property might be a more efficient way of getting the period, but I don’t have enough experience with them to help in your specific case.

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

Sidebar

Related Questions

In my view of my iPhone app, I have added one sub view, which
I have a table which I am printing. I have added borders to all
I have added a category to my Xcode project using File > New >
I have added a method foo to a class MYCustomClass in a category Category1
I have added a new field named category with a text box in Catalog
I have a custom category (disciplines) in my method plugin which I want to
I have two models : Category and Picture which refers to two tables, Categories
I have got a category - model which i am using it for my
I have added a category |Home| however when hitting the link it redirects to
I have added a category extension to my NSString class. The method basically formats

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.