1
var objectiveCString : NSString? = "objectiveCString"

var copiedObjectiveCString : NSString = objectiveCString!;

copiedObjectiveCString = "changedobjectiveCString"

print(copiedObjectiveCString);

print(objectiveCString!)

And output is

changedobjectiveCString
objectiveCString

Output should be

changedobjectiveCString
changedobjectiveCString

Because NSString is class type object and both string are now pointing to same location and value of one string is changed at the location then other string should also changed.

Himan Dhawan
  • 894
  • 5
  • 23

0 Answers0