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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:22:46+00:00 2026-05-26T18:22:46+00:00

I am creating an app that starts with a CGRect that is the size

  • 0

I am creating an app that starts with a CGRect that is the size of the screen. when the users touches inside of the CGRect it is cut into two CGRects. I get this to work just fine when I touch inside of the new CGRect that is created, but when I touch within a CGRect that is not the latest one added to the rectangleArray the app crashes and says sigabrt.

Here is the code in touchesBegan, blockPoint is the point where the screen is touched

for (NSValue *val in rectangleArray){
    CGRect rectangle = [val CGRectValue];
    if (CGRectContainsPoint(rectangle, blockPoint)) {
        CGRect newRectangle;
        CGRect addRectangle;
        if (!inLandscape) {
            newRectangle = CGRectMake(rectangle.origin.x, rectangle.origin.y, rectangle.size.width, blockPoint.y - rectangle.origin.y);
            addRectangle = CGRectMake(rectangle.origin.x, blockPoint.y, rectangle.size.width, rectangle.size.height - (blockPoint.y - rectangle.origin.y));

        }
        else {
            newRectangle = CGRectMake(rectangle.origin.x, rectangle.origin.y, blockPoint.x - rectangle.origin.x, rectangle.size.height);
            addRectangle = CGRectMake(blockPoint.x, rectangle.origin.y, rectangle.size.width - (blockPoint.x - rectangle.origin.x), rectangle.size.height);
        }
        [rectangleArray replaceObjectAtIndex:[rectangleArray indexOfObject:val] withObject:[NSValue valueWithCGRect:newRectangle]];
        [rectangleArray addObject:[NSValue valueWithCGRect:addRectangle]];
    }
}

Why is this crashing?

  • 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-26T18:22:47+00:00Added an answer on May 26, 2026 at 6:22 pm

    You’re trying to mutate the array (with “replaceObjectAtIndex:”) while enumerating it (the “for loop” at the beginning of your code). This rises an exception. You should see it in the console log, something like this:

    Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection  was mutated while being enumerated.
    

    What you can do instead is to first enumerate, then identify the objects you want to mutate, store them in another collection class (a NSSet or another NSArray) and finally apply the collected items in the original array.
    Or another possibility is you make a copy of the first array, then enumerate the copy and do the changes to the original array.

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

Sidebar

Related Questions

I'm creating an app that lets users take and store photos in a Core
I am creating an app that has three tabs on the main screen. Each
I'm creating an app that creates buttons through code when an activity starts (the
I'm creating and app that will rely on a database, and I have all
I am creating an app that is having a UIWebView which contains an advert.
I am creating an app that runs on the logitech revue. The UI is
I'm creating an app that creates and saves images. Currently I am saving them
I'm creating an app that tracks your elevation. Currently IOS is one of the
I am new to the iphone platform and am creating an app that retrievals
I am programming for iPhone, creating an app that shows various locally stored HTML

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.