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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:25:21+00:00 2026-05-15T15:25:21+00:00

I have a dynamically typed member id currentEvent in my view controller class. The

  • 0

I have a dynamically typed member id currentEvent in my view controller class. The rationale is that the view controller is used to display data for two model classes that are very similar.

I have a setter:

-(void)setCurrentEvent:(id)e {
    [self.currentEvent release];
    Class eventClass = [e class];
    currentEvent = [[eventClass alloc] init];
    currentEvent = [e retain];
}

Now I want to access a member of the class:

    return [currentEvent.comments count];

But the compiler complains: request for member 'comments' in something not a structure or union.

I am afraid I have a fundamental misconception about dynamic typing, but I hope it’s something much simpler.

  • 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-15T15:25:21+00:00Added an answer on May 15, 2026 at 3:25 pm

    Some problems with your setter: (1) don’t call the getter (self.currentEvent) when releasing the ivar, (2) always retain the new obj before releasing the old obj, in case it is the same obj, ie:

    -(void)setCurrentEvent:(id)e {
        [e retain];
        [currentEvent release];
        currentEvent = e;
    }
    

    That aside, I don’t understand what your trying to do with dynamic typing.

    This line will cause a compiler warning because you’ve told it that currentEvent is an id, which doesn’t have a comments member, so it rightly complains:

    return [currentEvent.comments count];
    

    If somehow you know that the id currentEvent is actually an object of a particular class that has a comments you can cast the id to another type to avoid the warning:

    return [(CommentEvent*)currentEvent.comments count];
    

    But before you do that, how do you know? You could check to see if it is the right class:

    if ([currentEvent isKindOfClass:[CommentEvent class]]) {
       ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why are programs that have dynamically typed languages usually interpreted rather than compiled?
I have a class called set that is a dynamically allocated array in the
I am going to make a GUI that will have dynamically created sets of
I have a dynamically created DataGridView that has a valid DataSource with one row
I have a dynamically inflated layout. <TableLayout> <!-- Two more tablelayout here --> <ScrollView>
It seems pretty common to me to have an argument, in a dynamically typed
I know that IronPython is a dynamically typed language so what I am asking
OK so I have made a class called Courses with private member functions courseName,
I have assembly A that depends (statically) on type T (reference type, a class)
I have an updatepanel, with a bunch of things in that are generated dynamically.

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.