Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As Squeegy said, all of the above methods you reference return autoreleased objects. The second code example will crash because you are overreleasing the string objects.</p> <p>Squeegy pointed one way of handling this, using NSMutableStrings. I'd recommend that approach. For example, the following rewrite of your method:</p> <pre><code>-(NSString*) unescape:(NSString*)string { NSMutableString *unescapedString = [[NSMutableString alloc] initWithString:string]; [unescapedString replaceOccurrencesOfString:@"&amp;apos;" withString:@"'" options:0 range:NSMakeRange(0, [unescapedString length])]; [unescapedString replaceOccurrencesOfString:@"&amp;amp;" withString:@"&amp;" options:0 range:NSMakeRange(0, [unescapedString length])]; [unescapedString replaceOccurrencesOfString:@"&amp;quot;" withString:@"\"" options:0 range:NSMakeRange(0, [unescapedString length])]; [unescapedString replaceOccurrencesOfString:@"&amp;gt;" withString:@"&gt;" options:0 range:NSMakeRange(0, [unescapedString length])]; [unescapedString replaceOccurrencesOfString:@"&amp;lt;" withString:@"&lt;" options:0 range:NSMakeRange(0, [unescapedString length])]; return [unescapedString autorelease]; } </code></pre> <p>only returns an autoreleased NSMutableString at the end. </p> <p>Even better would be if you passed in a pointer to an NSMutableString pointer (NSMutableString **). That way, you could modify the string that you'd created outside of your method without creating a new temporary string. If this seems strange, take a look at methods that deal with NSError instances as an example.</p> <p>EDIT: Ignore my statement about needing a double pointer in the previous paragraph. As erikprice points out, you just need to pass in an NSMutableString pointer. The double pointer is only needed if you create a new NSMutableString instance in your method to replace the one being passed in, which is not the case here.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload