advertisement

Article:
  Strings in Cocoa, Part 2
Subject:   NSStrings are mutable, just not by us?
Date:   2001-07-20 14:09:04
From:   tophu
I am confused. The information presented here seems to be in direct contradiction.


On the first page we do this:


NSString *path = @"Users/mike/textFile";
path = [path stringByAppendingPathExtension:@"txt"];


Then, on the second page, Mike says 'we cannot use the @"..." construct to directly create mutable strings. Remember that this construct created strings that are compiled and are always present. Obviously we cannot change a pre-compiled string...'


So, NSStrings can be modified by Cocoa internally, but not modified directly by us?


Or, perhaps, in the above example path is a pointer that points to address A in memory when it is created, and then when the +stringByAppendingPathExtension: method changes path, it is in fact changing the address that path pointer points to in memory to reference a different object. However, when we change an NSMutableString we are not changing the address value in the pointer, just the value of the object at that address.


Can someone clarify this for me?


1 to 1 of 1
  1. Michael Beam photo NSStrings are mutable, just not by us?
    2001-07-20 21:41:05  Michael Beam | O'Reilly Author [View]

1 to 1 of 1