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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:24:34+00:00 2026-05-19T02:24:34+00:00

i am going to just add one UILabel into array as example NSMutablearray *labels

  • 0

i am going to just add one UILabel into array as example

NSMutablearray *labels = [[NSMutableArray alloc] init];
UILabel *newLabel = [[UILabel alloc] initWithFrame:CGRectMake(100,100,20,20)];
newLabel.center = CGPointMake(100, 100);
[labels addObject:newLabel];

then later i want to change newLabel.center by doing something like this

[labels objectAtIndex:1].center.x +=10;

this gives me an error “request for member “center” in something not a structure or union”
then i try

    [labels objectAtIndex:1]->center.x +=10;

then this gives me another error said struct objc_object has no member named ‘center’

how can i change the property of UILabel that is store in NSMutableArray?

  • 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-19T02:24:35+00:00Added an answer on May 19, 2026 at 2:24 am

    You are getting this error because the return type of objectAtIndex: is simply id (which can be any object); NSArray is a generic container, when you retrieve an object from it, there’s no way to know what type it is. You know, because you put the objects in it, but the compiler doesn’t know.

    You wrote:

    [labels objectAtIndex:1].center.x +=10;
    

    That’s technically correct, but the compiler can’t type check it. It’s equivalent to writing this:

    id object = [labels objectAtIndex:1];
    object.center.x +=10;
    

    The second line is where the error occurs: the compiler knows object is an Objective-C object, but it doesn’t know what class, so it doesn’t know what properties have been defined, etc. So instead it tries to parse it as a structure field member access, which it’s not, and it fails.

    If you instead write:

    UILabel *label = [labels objectAtIndex:1];
    label.center.x +=10;
    

    Now the compiler knows that label is an instance of UILabel, it knows about the property definitions, and it can generate the correct code.

    Now you have a second problem, because you are changing a value within a structure. The second line above is shorthand for:

    label.center.x = label.center.x + 10;
    

    This is again shorthand for a Objective-C method call:

    [label center].x = [label center].x + 10;
    

    Because the center point is a CGPoint struct, you have to get/set the entire point value at once, you can’t just update the x or y member. So again, you need to do it like this:

    UILabel *label = [labels objectAtIndex:1];
    CGPoint c = label.center;
    c.x += 10;
    label.center = c;
    

    That will do what you want.

    If you’re tempted to say Objective-C is a stupid language because you need all the temporary variables… well, maybe, but be fair and understand you hit on two special cases in one example.

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

Sidebar

Related Questions

No related questions found

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.