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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:34:27+00:00 2026-05-25T06:34:27+00:00

One part of the program takes text from a uitextfield, copies it to a

  • 0

One part of the program takes text from a uitextfield, copies it to a mutable string and then performs

     sharedManager.ce_name=name.text


    [sharedManager.ce_name replaceOccurrencesOfString:@" " withString:@"%20"
     options:NSLiteralSearch range:NSMakeRange(0, [sharedManager.ce_name length])];

At this point it always gave me “attempt to mutate immutable object” – it was not random

The first time I got this error I changed it to

    sharedManager.ce_name=(NSMutableString *)name.text

This STILL gave me the attempt to mutate immutable object error, but it would occur randomly – weird right?

I then changed it to

    NSMutableString *mutable_name = [NSMutableString stringWithString:name.text];

    sharedManager.ce_name=mutable_name;

It has yet to fail on me doing it this way but I am convinced that I have not found the solution.

my questions:

1) Could that fact that it was doing it randomly after the first fix indicate I have some deep seated memory management problem?

2) Why didn’t the C-style cast fix it?

3) Will my current fix work?

Thanks for your time 🙂

  • 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-25T06:34:28+00:00Added an answer on May 25, 2026 at 6:34 am

    The problem here is the way in which you’re using casting. When you cast a pointer, it just starts treating the memory at that location as though it were a block of data representing that type.

    So if I’ve got a pointer to a Car class: Car* mycar;, and I cast it to a Person object: (Person*)mycar;, the program will try to access the memory there as though it was pointing at a Person object. However, a car is not a person, except in an old TV sitcom, so when it tries to access members on this or call functions, it’s going to try to go to a memory location that contains something other than what it’s expecting, and undefined things happen (generally, crashing).

    NSMutableString and NSString are incompatible in this regard, and so casting from one to the other will result in terrible times. Your fix ([NSMutableString stringWithString:]) is the correct solution.

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

Sidebar

Related Questions

I'm writing a program that for one part asks for the program to print
I am writing a GUI program. In one part of it I show an
I'm making one part in my app where if you push the button then
I want to relocate some controls from one part in the visual tree to
I'm working on project. One part of it is read given folders files. Program
one part of my applikation covers an MkMapview. Therefore i load a list of
MySqlDb is a fantastic Python module -- but one part is incredibly annoying. Query
I have some code that at one part will get executed a lot, and
I have an ASP.NET MVC application that has one part where I dont really
I am attempting to wrap my head around one part of the Objective-C memory

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.