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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:23:25+00:00 2026-05-23T04:23:25+00:00

I was looking at a piece of code today and notice that this particular

  • 0

I was looking at a piece of code today and notice that this particular coder use dot notation to access instance methods (these methods don’t take values, they just return value).

For example:

@interface MyClass : NSObject {

}
-(double)add;
@end

@implementation MyClass
-(double)valueA {
    return 3.0;
}

-(double)valueB {
    return 7.0;
}

-(double)add {
    return self.valueA + self.valueB;
}    
@end

He did this through out his code and the compiler doesn’t complain, but when I try it in my code like the example above I get the following error: “Request for member “valueA” in something not a structure or union”. What am I missing, any idea?

  • 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-23T04:23:26+00:00Added an answer on May 23, 2026 at 4:23 am

    The dot syntax is usually applied to declared properties but that’s not mandatory. Using obj.valueA and obj.valueB does work.

    The error message you’re getting is probably due to the object not having explicit type MyClass *. For example, the following works:

    MyClass *obj1 = [MyClass new];
    NSLog(@"%f %f %f", obj1.valueA, obj1.valueB, [obj1 add]);
    

    On the other hand:

    MyClass *obj1 = [MyClass new];
    NSLog(@"%f %f %f", obj1.valueA, obj1.valueB, [obj1 add]);
    
    id obj2 = obj1;
    NSLog(@"%f %f %f", obj2.valueA, obj2.valueB, [obj2 add]);
    

    gives:

    error: request for member ‘valueA’ in something not a structure or union
    error: request for member ‘valueB’ in something not a structure or union
    

    because obj2 has type id, so the compiler doesn’t have enough information to know that .valueA and .valueB are actually the getter methods -valueA and -valueB. This can happen if you place objects of type MyClass in an NSArray and later retrieve them via -objectAtIndex:, since this method returns a generic object of type id.

    To appease the compiler, you need to cast the object to MyClass * and only then use the dot syntax. You could accomplish this by:

    MyClass *obj2 = obj1;
    // or
    MyClass *obj2 = [someArray objectAtIndex:someIndex];
    // and then
    obj2.valueA
    

    or, if obj2 is declared as id:

    ((MyClass *)obj2).valueA
    

    or, if the object is returned by a method whose return type is id:

    ((MyClass *)[someArray objectAtIndex:someIndex]).valueA
    

    Alternatively, you could simply get rid of the dot syntax altogether (my favourite):

    [obj2 valueA]
    [[someArray objectAtIndex:someIndex] valueA]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for a ready-to-use piece of code that would be able to read
I am looking at this piece of code. This constructor delegates to the native
I'm looking to embed a piece of code that will print out the time
Strangly enough, this small piece of code throws the above mentioned Exception. Also, looking
I am looking for a piece of code Python code that would give me
I was looking at this piece of code and can not understand what the
I have been looking at this piece of code for the last 3 hours
I'm looking to optimized this piece of code. It will process 15000 - 20000
I am currently looking a this piece of code from a module called ZfcUser
I am looking at a piece of code, and i can see that the

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.