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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:51:45+00:00 2026-05-27T19:51:45+00:00

I have a hierarchy of model objects which I will be displaying on different

  • 0

I have a hierarchy of model objects which I will be displaying on different type of UITableViewCell subclasses. All decision is made on the fly as to which model object should be used and corresponding UITableViewCell subclass’ object is spawned and then set the model object to the UITableViewCell’s subclass object so that it can fetch values from it.

My UITableViewCell hierarchy is something like this:

The base class Cell hierarchy:

@interface BaseCell : UITableViewCell
{
  Base *baseObj_;
}
@end

The subclass of cell hierarchy:

@interface DerivedCell : BaseCell
{
}
@property (nonatomic, retain) Derived *derivedObject;
@end

@implementation DerivedCell
@synthesize derivedObject = baseObj_;
@end

The base class of Model object:

@interface Base : NSObject
{
  NSString *title_;
}
@property (nonatomic, retain) NSString *title;
@end

The subclass of model hierarchy

@interface Derived : Base
{
  NSString *detailedText_;
}
@property (nonatomic, retain) NSString *detailedText;
@end

When I do so, I am having errors in this line:

@synthesize derivedObject = baseObj_;

Which reads:

  1. Property ‘derivedObject’ attempting to use ivar ‘baseObj_’ declared in super class BaseCell.

  2. Type of property ‘derivedObject’ (Derived*) does not match type of ivar ‘baseObj_’ (‘Base * __strong’)

I want to use properties and synthesize them so that I can leverage the uses of properties (like using dot notation etc.). I have for now used accessors and setters which solves the problem:

@interface DerivedCell : BaseCell
{
}
-(Derived*)derivedObject;
-(void)setDerivedObject:(Derived*)newDerivedObject;
@end

But I was just wondering if I could somehow fix these errors to use the properties only.

Thanks,
Raj

  • 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-27T19:51:46+00:00Added an answer on May 27, 2026 at 7:51 pm

    Try the below code I have modified your code a bit as shown below

    Since you can assign class Base object to class Derived in @synthesize, it can be achieved by this way, I know you have tried it already, I have tried it with the below code and able to access the variables with dot, try the below code and let me know if it is not working

    @interface DerivedCell : BaseCell
    {
        Derived *derivedObject;
    }
    @property (nonatomic, retain) Derived *derivedObject;
    
    @end
    
    @implementation DerivedCell
    @dynamic derivedObject;
    - (void)setDerivedObject:(Base *)baseObj {
        if (self.derivedObject == nil) {
            derivedObject = [[Derived alloc] init];
        }
        derivedObject.detailedText = baseObj.title;
    }
    - (Derived *)derivedObject {
    
        return derivedObject;
    }
    
    @interface Derived : Base
    {
        NSString *detailedText_;
    }
    @property (nonatomic, retain) NSString *detailedText;
    @end
    
    @implementation Derived
    @synthesize detailedText = detailedText_;
    @end
    
    @interface BaseCell : UITableViewCell
    {
        Base *baseObj_;
    }
    @property (nonatomic, retain) Base *baseObj;
    @end
    
    @implementation BaseCell
    @synthesize baseObj = baseObj_;
    @end
    
    @interface Base : NSObject
    {
        NSString *title_;
    }
    @property (nonatomic, retain) NSString *title;
    @end
    
    @implementation Base
    @synthesize title = title_;
    @end
    
    
        Base *b = [[Base alloc] init];
        b.title = @"Hello Raj";
        BaseCell *bc = [[BaseCell alloc] init];
        bc.baseObj = b;
    
        DerivedCell *dc = [[DerivedCell alloc] init];
        dc.derivedObject = b;
    
        NSLog(@"Derive dc %@", dc.derivedObject.detailedText);
    

    Another Solution which I have provided has an issue when I checked it

    @interface BaseCell : UITableViewCell
        {
            NSString *baseTitle_;
        }
        @property (nonatomic, retain) NSString *baseTitle;
        @end
        @implementation BaseCell
        @synthesize baseTitle = baseTitle_;
        @end
    
    
        @interface DerivedCell : BaseCell
        {
            NSString *derivedTitle_;
        }
        @property (nonatomic, retain) NSString *derivedTitle;
    
        @implementation DerivedCell
        @synthesize derivedTitle = baseTitle;
        @end
    

    When I created instance for the class and as shown below

    DerivedCell *dCell = [[DerivedCell alloc] init];
    
    dCell.baseTitle = @"Hello";
    
    NSLog(@"%@",dCell.baseTitle);//Output was Hello
    NSLog(@"%@",dCell.derivedTitle);//Output was (null)
    

    It didn’t assign the value to derivedTitle, If it is working for you please let me know


    Another solution with memory referncing

    @interface BaseCell : UITableViewCell
    {
        NSMutableString *baseTitle_;
    }
    @property (nonatomic, retain) NSMutableString *baseTitle;
    @end
    
    @implementation BaseCell
    @synthesize baseTitle = baseTitle_;
    @end
    
    @interface DerivedCell : BaseCell
    {
    
    }
    
    @property (nonatomic, retain) NSMutableString *derivedTitle;
    @end
    
    @implementation DerivedCell
    @synthesize derivedTitle;
    - (id) init
    {
        if ( self = [super init] )
        {
            baseTitle_ = [[NSMutableString alloc] init];
            derivedTitle = baseTitle_;
        }
        return self;
    }
    
    @end
    
        DerivedCell *dCell = [[DerivedCell alloc] init];
    
        [dCell.baseTitle appendString:@"Hello"];
    
        NSLog(@"baseTitle : %@",dCell.baseTitle);
        NSLog(@"derivedTitle :%@",dCell.derivedTitle);
    

    Console Output baseTitle : Hello derivedTitle :Hello

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

Sidebar

Related Questions

I have a hierarchy of tables 3 levels deep (QualificaionType has many QualificationGroups, which
I have a rather deep hierarchy of objects that I'm trying to persist with
I have object , tree/model/hierarchy, whatever the correct term is. It consists of what
(I am new to paperclip) I have this model hierarchy: base model: class QuestDescription
I have hierarchical data stored in the datastore using a model which looks like
I have a legacy database, which I am using EJB3 to model. The database
Is there a preferred way to create a hierarchy of new ActiveRecord model objects
I have this Core Data Model Hierarchy, with the respective relationships to each other:
I have a doctrine class User which is of this hierarchy Doctrine_Record -> BaseUser
I have an ASP.Net MVC application with a model which is several layers deep

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.