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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:13:41+00:00 2026-05-29T12:13:41+00:00

for(UIView *view in [_scrollView subviews]) { NSMutableArray *_mutableArray = [_array mutableCopy]; [_mutableArray filterUsingPredicate:[NSPredicate predicateWithFormat:@guid

  • 0
for(UIView *view in [_scrollView subviews]) {
    NSMutableArray *_mutableArray = [_array mutableCopy];
    [_mutableArray filterUsingPredicate:[NSPredicate predicateWithFormat:@"guid like %@",view.object.guid]];
    if([_mutableArray count] != 0) {
        //object is already on screen we need to update it
        [view setObject:(Object*)[_mutableArray objectAtIndex:0]];
    }
    else {
        //object not on screen add it 
         _mutableArray = [_array mutableCopy];
        [_mutableArray filterUsingPredicate:[NSPredicate predicateWithFormat:@"guid not like %@",view.object.guid]];

        UIView *newView = [[UIView alloc] initWithObject:(Object*)[_mutableArray objectAtIndex:0]];
        [_scrollView addSubview:newView];

    }
}

As you can see this method updates the objects that are on screen and if an object is not on screen it is created and added to the scrollView subview hierarchy.
Now my concern is that I’m modifying the scrollView subviews hierarchy while enumerating it. Will this crash my app eventually?

If yes, how can I modify the above code to be safe and achieve the same functionality?

Thanks!

  • 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-29T12:13:43+00:00Added an answer on May 29, 2026 at 12:13 pm

    Will this crash my app eventually?

    Perhaps. The answer in this particular case would be in how UIScrollView returns its list of subviews. If it makes a copy or a new array from it’s list of subviews and returns that, then no, it won’t crash. If it returns the same array it’ll later update when you addSubview:, then you’re playing with fire.

    Unless it’s documented otherwise, mutating a collection you’re enumerating is a bad idea. Make a copy of it first and enumerate that instead.

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

Sidebar

Related Questions

for(UIView *subview in [scrollView subviews]) { NSLog(@subviews Count=%d,[[scrollView subviews]count]); //[subview release]; [subview removeFromSuperview]; }
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { if(section != 0) { UIView *view = [[[UIView
in my application the first view is an UIView with a couple of uilabel
I'm animating a UIView's frame property using a CAKeyframeAnimation on the view's CALayer and
I'm asking my ViewController for it's view.center property and drawing a new UIView that
I want to add a UIView of smaller frame as subview to parental view
I'm implementing a UIView's (UITableViewCell to be more exact) drawRect method. My view has
I have a UIView in a scrollview that contains about 100 subviews. The subviews
how do i remove all subviews from my scrollview... i have a uiview and
In my program there is two views(scrollView-super, view-sub*2). In my case two subviews are

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.