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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:32:07+00:00 2026-05-30T03:32:07+00:00

What does the expression -= do? I spent the last hour trying to fix

  • 0

What does the expression -= do?

I spent the last hour trying to fix a bug which ended up including -= in itself:

[self.myArray objectAtIndex:myButton.tag -= 1];

I’m not sure what that expression does, is it supposed to be similar to +=?

The truly mystifying part is if I NSLog() it, it borks my results:

NSLog(@"data with -=: %@", [self.myArray objectAtIndex:((UIButton *)sender).tag -= 1]);

When I comment just that line out, it works like it should. if I un-comment that line, I can’t get the index location I want. I’m not 100% sure what it does to my array, but there is no reason that I can think of that when I just log it, that it would effect other parts of the code.

  • 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-30T03:32:08+00:00Added an answer on May 30, 2026 at 3:32 am

    Explained:

    [self.myArray objectAtIndex:myButton.tag -= 1];
    

    The -= operator lvalue -= rvalue is interpreted as lvalue = lvalue - rvalue. So, here your code can be written as:

    [self.myArray objectAtIndex:myButton.tag = myButton.tag - 1];
    

    An assignment statement (=), in turn, evaluates to its left side, so after decreasing myButton.tag by one, it will be passed to objectAtIndex: as if it was:

    myButton.tag = myButton.tag - 1;
    [self.myArray objectAtIndex:myButton.tag]; // here myButton.tag is already decreased by one
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What does the expression Turing Complete mean? Can you give a simple explanation, without
^([0-9]*[1-9][0-9]*(\.[0-9]+)?|[0]+\.[0-9]*[1-9][0-9]*)$ I don't know regular expression well. Above regular expression does not allow input
Why does this lambda expression not compile? Action a = () => throw new
What does the following expression return in Java? Math.max(Float.POSITIVE_INFINITY, Double.POSITIVE_INFINITY); I saw this question
Is there a library for .NET that does parenthesis or expression reduction and optimization?
Does anyone have a regular expression handy that will match any legal DNS hostname
Does anyone have any suggestions (or a regular expression) for parsing the HTTP Accept
How does Python evaluate the expression 1+++2 ? How many ever + I put
Does anyone know if the following expression will be possible in the next version(s)
why does the following js expression: test1 foo bar test2.replace(/foo.bar/, $') result in 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.