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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:54:19+00:00 2026-06-18T12:54:19+00:00

NSScanner takes a pointer to an NSString: NSMutableString *myString; … [scanner scanUpToCharactersFromSet:charSet intoString:&myString]; [myString

  • 0

NSScanner takes a pointer to an NSString:

NSMutableString *myString;
...
[scanner scanUpToCharactersFromSet:charSet intoString:&myString];
[myString appendString:@"hello"];

But myString is mutable, so I get an error when I try to do an append later, saying I’m trying to mutate an un-mutatable.
Do I have to create temp copies and go back&forth, or is there a more efficient way to do this?

  • 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-18T12:54:20+00:00Added an answer on June 18, 2026 at 12:54 pm

    Either do

    NSString *myString; //this is just a variable identifier, no object was created and assigned to it yet
    ...
    //scanner will create a NSString and write it to myString. It won't know it is passed to a variable typed NSMutableString or NSString
    [scanner scanUpToCharactersFromSet:charSet intoString:&myString];
    
    //instead of creating mutable string you can create a new immutable by appending a string
    myString = [myString stringByAppendingString:@"hello"];
    

    or better: see the next code snippet

    NSMutableString *myString; //this is just a variable identifier, no object was created and assigned to it yet
    ...
    
    //scanner will create a NSString and write it to myString. It won't know it is passed to a variable typed NSMutableString
    [scanner scanUpToCharactersFromSet:charSet intoString:&myString];
    //myString contains a NSString now, not NSMutableString
    
    myString = [myString mutableCopy]; // make a mutable copy and assign it to the variable
    [myString appendString:@"hello"];
    

    In the second approach you will have the inconsistency that for a short while a NSMutable typed variable will hold a immutable string. tis is definitely a flaw. Solution one is much cleaner. If you favor two you should introduce a second NSString variable and pass that to the scanner an d than mutable copy that to your NSMutableString.

    NSString *tempString;
    NSMutableString *myString; 
    ...
    
    [scanner scanUpToCharactersFromSet:charSet intoString:&tempString];
    
    myString = [tempString mutableCopy];
    [myString appendString:@"hello"];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

NSString*test=[NSString stringWithString:inputString]; NSScanner*scan; BOOL pass= [scan scanUpToCharactersFromSet:[[NSCharacterSet alphanumericCharacterSet] invertedSet] intoString:&test]; The last line crashes
I created an NSScanner category method that shows a leak in instruments. - (BOOL)scanBetweenPrefix:(NSString
oauth_token=requestkey&oauth_token_secret=requestsecret How can I use NSScanner to get requestkey and requestsecret. I can't seem
I want to get the double value from 1.04E-4 NSString, but I didn't manage
As the title. I tested NSScanner, but it passed some strange strings. (ex :123aaa).
NSString *markdown = @This is the *Markdown* syntax.; NSScanner *aScanner = [NSScanner scannerWithString:markdown]; if
how do I parse a mail in Cocoa? I've read the NSScanner tutorial, but
I am working with NSScanner to parse data that is both comma and line
I have a MongoDB query that's taking an unreasonably long time to run, but
I have an nsstring with 50 of lines i want to scan a particular

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.