setValue points to the object instead of copying the NSString

I'm parsing an XML document. I have an NSMutableString to hold the value for each node I'm passing through and for specific nodes - I want to update the NewsElement class.

This is my code:

[newsElement setValue:currentElementValue forKey:elementName];

The currentElementValue is the NSMutableString the the elementName is key I want to update. Each field is NSString. The problem is that instead of copying the string, now my NSString points to the currentElementValue address so all of the fields are always the same...

Answers


Presumably copying currentElementValue would fix your problem. Have you tried:

[newsElement setValue:[currentElementValue copy] forKey:elementName]; 

This will make an immutable copy (i.e. an NSString) of the currentElementValue which is an NSMutableString. If you need the copy to be mutable you could use the mutableCopy method instead, for example:

[newsElement setValue:[currentElementValue mutableCopy] forKey:elementName]; 

Need Your Help

specify null value for F# Deedle

f# deedle

is it possible to specify a customised value to represent null or NaN when loading csv into Deedle data structure? in Python pandas, this is a configurable list option.

instantiate object with array elements as parameters java

java reflection ioc-container instantiation

I am making an IoC Container in java, using reflection, to auto instantiate dependencies. I've got it working, recursively, but the instantiation is clumsy and not very intuitive.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.