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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:35:45+00:00 2026-06-12T14:35:45+00:00

Describing Core Data Model: I have a Core data model for my Expense tracking

  • 0

Describing Core Data Model:

I have a Core data model for my Expense tracking application. I made an abstract parent entity named “Money” with attributes “vendor”, “date”, “amount” and so on. The two sub-entities “Expense” and “Income” inherit from the parent entity “Money”. Then there are other entities such as “Category” and “subCategory” with their attributes. Total as of now: 5 entities in my data model.

I have a relationship from the sub-entities “Expense” and “Income” to entity “Category” which in turn has a to-many relationship with the entity “SubCategory” as a category can have one or many sub-categories. The entity “Category” has a to-many relationship to the entities “Expense” and “Income” as well as there can be may expenses or incomes for a particular category. That makes sense to me as of now.

I have a Table-view and using NSFetchedResultsController to fill my table-view with the mix od expenses and Incomes.

I have an alert view with buttons “ExpenseS” and “Income” – both are pushed to a same view controller which has the details like fill a vendor, amount, category, sub-category and SAVE button on the navigation bar.

That’s my save method:

- (void)saveMoney:(id)sender
{    
    AppDelegate * applicationDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];

    NSManagedObjectContext * context = [applicationDelegate managedObjectContext];

    _money = (Money*) [NSEntityDescription insertNewObjectForEntityForName:@"Money" inManagedObjectContext:context];

    double expenseAmt = [_amountTxtField.text doubleValue];

    NSDate *expenseDate = [dateFormatter dateFromString:[NSString stringWithFormat:@"%@",currentDateLbl.text]];

    _money.vendor = vendorTxtField.text;
    _money.cat = categoryLbl.text;
    _money.subcat = subCategoryLbl.text;
    _money.amount = [NSNumber numberWithDouble:expenseAmt];
    _money.date = expenseDate;
    _money.photo = _templateImgView.templateImage.image;
    _money.notes = notesLbl.text;
    _money.paidBy = paidResourceLbl.text;

    NSError * error = nil;
    [context save:&error];

    [self.navigationController dismissModalViewControllerAnimated:YES];

}

This saves the new expense/income to the table-view and I get a mix of the results(expenses/income) in my table view. But how will I know if my row is an expense or an income. I think a fetch request should make it work? But where this fetch request should be placed, in what method? I tried using the following code:

AppDelegate * applicationDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
NSManagedObjectContext * context = [applicationDelegate managedObjectContext];

// Retrieve the entity from the local store -- much like a table in a database
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Money" inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];

[request setEntity:entity];
[request setIncludesSubentities:YES];

// Set the sorting -- mandatory, even if you're fetching a single record/object
NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:YES];

NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor1,nil];
[request setSortDescriptors:sortDescriptors];
[sortDescriptors release]; sortDescriptors = nil;
[sortDescriptor1 release]; sortDescriptor1 = nil;

NSError * error;

NSArray * objects = [context executeFetchRequest:request error:&error];

for (Money* money in objects)
{
    NSLog(@"money class");

    if([money isKindOfClass:[Expense class]])
    {
        NSLog(@"expense class");
    }
    else
    {

    }
}

[context save:&error];

This never prints the “expense class”, doesn’t go there at all. I don’t know how this shall work and in what method I shall place this fetch request.

Please help me out here. I will appreciate it.

Thank you

  • 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-12T14:35:46+00:00Added an answer on June 12, 2026 at 2:35 pm

    When you create your entities you should use Expense or Income as the entity name, e.g.:

    [NSEntityDescription insertNewObjectForEntityForName:@"Expense" inManagedObjectContext:context];
    

    Then when you fetch using the entity name ‘Money’ it’ll pull out the sub-entities as you’re expecting.

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

Sidebar

Related Questions

Lets say I have a table describing cars with make, model, year and some
I have strings describing a range of characters alphabetically, made up of two characters
The best way of describing this is I have a table of people with
I have a range of weekly variables describing a person's status (from week 1,
I have patch file describing changes to multiple files to apply to the contents
I have a table describing files with a datetime field. I want to somehow
In a dialog describing my change log, I'd like to have some links to
I hope I am describing my issue enough.. here goes: I have a YUI
I have a WPF xaml file describing a section of a GUI and I'd
I have trouble describing my problem so I'll give an example: I have a

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.