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

  • Home
  • SEARCH
  • 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 8208931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:32:28+00:00 2026-06-07T09:32:28+00:00

I have a situation where I’ve created an NSArray of NSManagedObjects that are all

  • 0

I have a situation where I’ve created an NSArray of NSManagedObjects that are all derived from CoreData entities. The problem is that there are multiple entities in this array, but each of the entities in the array have a “name” property that I would like to retrieve.

I come from a C++ background, and if I were facing this problem I would make another class with properties I’d like to use and have all the child objects inherit from NSManagedObject and that class with the property I like. Unfortunately, I can’t see a way to do that with Objective C, as it doesn’t support multiple inheritance and I can’t figure out the paradigm to deal with little OOP problems like this. 🙁

—Background—

The use case scenario for what I’m dealing with is that I would like to fill a UITableView with cells from various characters from various object types. All the characters have a name, but they are all unique object types. Right now I can do one type just fine like this:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"CharNameCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    CharacterWizard *wizards = (CharacterWizard*)[self.characters objectAtIndex:indexPath.row];
    cell.textLabel.text = wizards.name;

    return cell;
}

But, as you can see, this breaks down when I have different types. I”m sure there’s a more elegant solution to deal with this problem, but previous experience with other languages is getting in my way here (I think). Hope this wasn’t too long of a question.

  • 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-07T09:32:30+00:00Added an answer on June 7, 2026 at 9:32 am

    One approach would be to define a Character class, and make CharacterWizard and other, similar classes into subclasses of Character:

    @interface Character : NSManagedObject
    @property (nonatomic, strong) NSString *name;
    @end
    
    @interface CharacterWizard : Character
    @property (nonatomic, strong) NSMutableArray *spells;
    @end
    
    @interface CharacterFighter : Character
    // ...
    @end
    

    Another approach would be to use a protocol, and have all of your NSManagedObjects implement the protocol. For instance, your protocol could be:

    @protocol HasName
    @property (nonatomic, strong) NSString *name;
    @end
    

    …then your CharacterWizard class would declare that it implements (and would proceed to implement) HasName:

    @interface CharacterWizard : NSManagedObject <HasName>
    

    …and then your code can reference a generic object that implements the HasName protocol (and can invoke the protocol’s methods) without knowing the actual class of the object:

    id <HasName> jenkins = [self.characters objectAtIndex:indexPath.row];
    cell.textLabel.text = jenkins.name;
    

    I’d probably recommend the Character option if your other classes are CharacterFighter, CharacterRogue, and so on. If the name property is the only thing your classes have in common, then the protocol would make more sense.

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

Sidebar

Related Questions

I have situation where I want to extract multiple values from multiple source objects
I have situation where there are multiple test cases which uses a common method.
I have situation, where running a query that filters by an indexed column in
I have situation in which I read a record from a database. And if
We have situation where say we have four engineers that are working on software
I have situation where I need to make sure that user has completed certain
I have situation. I have to create a Sports Club system in JAVA. There
I have situation where I have to handle multiple live UDP streams in the
I have a situation where there is a program which is written in c++.
I have a situation where I currently have a huge spreadsheet that is used

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.