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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:01:25+00:00 2026-06-16T23:01:25+00:00

I want to set an object to ‘nil’ as I enumerate through an array,

  • 0

I want to set an object to ‘nil’ as I enumerate through an array, as follows:

for(Object* object in array){
    object = nil;
}

Xcode then tells me ‘Fast enumeration variables can’t be modified in ARC by default; declare the variable __strong to allow this.’

Which means doing this:

for(Object __strong* object in array){
    object = nil;
}

This seems to be redundant. As far as I understand, declaring a strong reference to an object increases its retain count by one, and nil-ing it decreases the retain count by one. So how, then, do I set an object to nil while enumerating through an array?

I am using ARC.

  • 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-06-16T23:01:26+00:00Added an answer on June 16, 2026 at 11:01 pm

    See Fast enumeration iteration variables in the Clang “Objective-C Automatic Reference Counting” documentation:

    If a variable is declared in the condition of an Objective-C fast
    enumeration loop, and the variable has no explicit ownership
    qualifier, then it is qualified with const __strong and objects
    encountered during the enumeration are not actually retained.

    Rationale
    This is an optimization made possible because fast
    enumeration loops promise to keep the objects retained during
    enumeration, and the collection itself cannot be synchronously
    modified. It can be overridden by explicitly qualifying the variable
    with __strong, which will make the variable mutable again and cause
    the loop to retain the objects it encounters.

    So by default, the loop variable is immutable, and the retain count of the current object is not increased for performance reasons.

    If you explicitly declare the loop variable as __strong, it is a mutable strong reference, and the retain count of the current object is increased, and setting the loop variable to nil decreases the retain count again. But doing so does not deallocate the object or remove it from the array, because the array holds another strong reference to the object.

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

Sidebar

Related Questions

I want to set a property of an object that is an array type.
I want to organize a set of Object ( MyPlugin ) in a TreeView
I'm going to be getting an array of objects and want to set instance
I have created a UIColor object and want to set the colors before drawing
Assuming you know about Python builtin property: http://docs.python.org/library/functions.html#property I want to re-set a object
Hey folks..!! I m using styleManager.setStyleDeclaration to set the CssStyleDeclaration object for more then
I'm writing a project in mvc 3. I want to set an object in
Imagine std::vector<std::vector<Objekt>> m_pole; We want to set every object to nullptr. But following code
I want to set the Background color of an object's style, to be the
I want to set attribute for a stdClass object in a single statement. I

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.