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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:16:16+00:00 2026-05-28T07:16:16+00:00

In my iPhone app I have two viewControllers: viewController1 has a tableView that shows

  • 0

In my iPhone app I have two viewControllers:
viewController1 has a tableView that shows a list of Item1 objects
viewController2 has a tableView that shows a list of Item2 objects

Where Item1 class and Item2 class inherit from the abstract class ParentItem.

Now I want to make Item2 object a NSManagedObject so I can save it on the device and make the viewController2 use a NSFetchedResultsController to load its tableView with Item2 objects.

But I don’t want Item1 to be a NSManagedObject, I want to use it as regular object.

The problem is that if I create ParentItem class as NSManagedObject then Item1 class will also be a NSManagedObject and I can’t use it as a regular object (I mean I wont be able to create an Item1 object with regular alloc-init, or can I???)

And if I create ParentItem class as regular NSObject, then Item2 class will also be regular NSObject.

  • 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-05-28T07:16:16+00:00Added an answer on May 28, 2026 at 7:16 am

    What you most likely need is an interface that the two class’s can implement. I’ll use the example of a person:

    @protocol PersonInterface <NSObject>
    
    @property (nonatomic, copy) NSString *firstName;
    @property (nonatomic, copy) NSString *lastName;
    
    @end
    

    Class inheriting from NSObject

    @interface NonManagedPerson : NSObject <PersonInterface>
    @end
    
    @implementation NonManagedPerson
    
    @synthesize firstName = _firstName;
    @synthesize lastName  = _lastName;
    
    @end
    

    Class inheriting from NSManagedObject

    @interface ManagedPerson : NSManagedObject <PersonInterface>
    @end
    
    @implementation ManagedPerson
    
    @dynamic firstName;
    @dynamic lastName;
    
    @end
    

    Now if an object needs to use either of these classes it does not care what it’s supertype it, it will only care that the object responds to -firstName, -lastName, -setFirstName or -setLastName.

    To allow this flexibility you need to be ensuring that the objects you want to use conform to the interface as you are no longer bothered about a specific type e.g.:

    @interface FootballClub : NSObject
    
    @property (nonatomic, retain) id<PersonInterface> clubManager;
    
    // .. other properties
    
    @end
    

    Update

    To get shared implementation you could consider composition/delegation.

    Composition

    You make another class that encapsulates the common work and then have it as an available as an ivar to be used in your class.

    Delegation

    Do the same as other common elements, such as UITableView. At certain points it calls out to it’s datasource (any element that implements the required methods of <UITableViewDatasource>) to ask for something to be done. You can then have two objects use the same class as a datasource and the implementation will be shared.

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

Sidebar

Related Questions

I actually have two questions regarding exception/error handling in the iPhone app that I
So in my iPhone app I'm building, I have two buttons that are going
I have an iPhone app, it has two separate MKMapView components in different views,
In my Iphone app I have to add textfield at two rows of tableview
In my iPhone app, I have two plist files to store Themes. One is
I have an iPhone app that hides the status bar. However, my main view
I have a simple iphone app that's based on the CrashLanding sample app. So
I have an iPhone app that compiles and runs fine in the Simulator on
I have an iPhone app running in the simulator that won't quit. I also
Say I have two NSTimers in my iPhone app: timer1 and timer2 . timer1

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.