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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:36:34+00:00 2026-05-23T22:36:34+00:00

the method enumerateAttributesInRange gets a block of code and executes it for every attribute

  • 0

the method enumerateAttributesInRange gets a block of code and executes it for every attribute in NSAttributedString

  • Does it call the bock asynchronously?

When The following method gets called twice in a row really quick 1 after the othr my app gets frozen, I am wondering of it’s because enumerateAttributesInRange runs the block of code asynchronously, so 2 threads are trying to modify my AttributedString at the same time.

- (void) doSomething
{
   //following line works fine
   [self doSomethingwithAttributedString];

   //following line works fine
   [self doSomethingwithAttributedString];
   [self performSelector:@selector(doSomethingwithAttributedString) withObject:nil afterDelay:1];

   //following crashes
    [self doSomethingwithAttributedString];
    [self doSomethingwithAttributedString];
}

- (void)doSomethingwithAttributedString
{
   [self.attributedString enumerateAttributesInRange:_selectedRange options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired usingBlock:
 ^(NSDictionary *attributes, NSRange range, BOOL *stop) {

          // Here I modify the dictionary and add it back to my attributedString
 }];
}
  • 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-23T22:36:34+00:00Added an answer on May 23, 2026 at 10:36 pm

    You are modifying the attributed string while it is being enumerated. I bet this thoroughly confuses the enumerator, since the attributed string it is working on is not in the state it was in when it started enumerating. In the block, only collect the attributes, e.g. in a dictionary or array, but modify them and apply them to the string afterward, i.e. after the enumeration is finished.

    In other words: don’t put code that modifies the attributed string inside the block that is called during enumeration. The docs say you can modify the attributed string inside the range on which the block applies, but ISTM you must take enormous care not to go outside. I wouldn’t do this.

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

Sidebar

Related Questions

Following method shall only be called if it has been verified that there are
Which method of the lifecycle is called when orientation changes occur? My application executes
Every method I write to encode a string in Java using 3DES can't be
What method do I call to get the name of a class?
A method I work with that is called tens of thousands of times started
the method didFinishLaunchingWithOptions is not being called when i launch via push notification on
each() method in jQuery contains such a statement: callback.call( value, i, value ) I
Every method accepts a set of parameter values. Should we always validate the non-nullness
The method below should return true for the first call, and false for any
The method - Entity Framework Code-First - looks good. But its very difficult to

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.