convert NSTaggedPointerString to NSString
NSTaggedPointerString
is already an NSString
, it's just a subclass. You can use it anywhere you can use an NSString
, without conversion.
I had this same issue multiple times. It would seem that type inference for NSDictionary is not an exact science. What I do is specifically ask if the object responds to a particular method. For example if I am looping through parsing some JSON and I am attempting to access a value of type NSString
:
NSString * string;
if ([[dict objectForKey:@"value"] respondsToSelector:@selector(stringValue)]) {
string = [[dict objectForKey:@"value"] stringValue];
}
else {
string = [NSString stringWithString:[dict objectForKey:@"value"]];
}
documentFile.documentRevision = string;
I have encountered places where NSTaggedPointerString
cannot be used as a NSString
, such as when creating an NSDictionary
. In those cases use stringWithString:
:
NSString* <# myNSString #> = [NSString stringWithString:<# myNSTaggegedString #>];