convert NSTaggedPointerString to NSString

nstaggedpointerstring crash
nstaggedpointerstring apple
nstaggedpointerstring objectforkey:: unrecognized selector sent to instance

I had called an interface of Baidu to check id Number, however the value of Sex returned with sex = M, without "" around the M in JSON, when I use NSString in module to store it and then print the class name of this sex property, it printed as NSTaggedPointerString, I doubt how to convert it to a String to use it. Anyone have good ideas?

NSTaggedPointerString is already an NSString, it's just a subclass. You can use it anywhere you can use an NSString, without conversion.

How to get String from a NSTaggedPointerString?, convert NSTaggedPointerString to NSString (5 answers). Closed 3 years ago. "​NSString *realStr = [NSString stringWithString:pilotCode];". The problem isn't converting that string to an int, the problem is that you haven't turned on essential warnings in your compiler, so it lets you get away with this nonsense. – gnasher729 Nov 2 '16 at 12:09

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 #>];

convert NSTaggedPointerString to NSString - objective-c, NSTaggedPointerString is already an NSString, it's just a subclass. You can use it anywhere you can use an NSString, without conversion. Could not cast value of type 'NSTaggedPointerString' to 'NSNumber' (NSTaggedPointerString is a subclass of NSString) , so you should convert String to Double.

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;

ObjC NSNumbers returned as NSTaggedPointerString, The problem is that NSDictionary isEqual fails because NSTaggedPointerString is an NSString type rather than an NSNumber. This project  This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site.

In my case son {"count":"123"} I got error. Solved:

// Data was created, we leave it to you to display all of those tall tales!
// NSLog(@«data: %@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);

NSDictionary * json  = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
if ([json isKindOfClass:[NSDictionary class]]){ //Added instrospection as suggested in comment.
                  NSArray *dicArray = json[@"count"];
                   NSLog(@"=:%@", dicArray);


Could not cast value of type 'NSTaggedPointerString' to - iOS, The reason of the error is jsonDict["totalfup"] is a String (NSTaggedPointerString is a subclass of NSString) , so you should convert String to Double. Please  2.0.5 Update Causes Errors With Type (expected NSNumber got NSTaggedPointerString) With Type (expected NSNumber got NSTaggedPointerString) hold a NSString.

for Swift 3 or 4

String(stringInterpolationSegment: taggedPointerString) 

NSInteger Mapping, NSValue but got NSTaggedPointerString , @property (copy, nonatomic) NSString *message; @property (assign, be of type NSString or use a transformer to attempt to convert the string  No pudieron echar valor de tipo ‘NSTaggedPointerString’ a ‘NSNumber’ Alguien sabe por qué? He intentado cambiar el tipo de propiedad a float y, a continuación, toda la estructura de la clase, pero todavía se produce el problema.

NSString, A static, plain-text Unicode string object that bridges to String ; use NSString when Returns an NSString object initialized by converting given data into UTF-​16  Initializes the receiver, a newly allocated NSString object, by converting the data in a given C-string from the default C-string encoding into the Unicode character encoding.

Could not cast value of type 'NSTaggedPointerString' to , The reason of the error is jsonDict["totalfup"] is a String, so you should convert String to Double. Please make sure, catch exception and check  Here it is expecting NSString instead of NSNumber so that is the reason it crashes.So convert that to NSString nstaggedpointerstring

How to convert a string to an NSString, When Swift originally launched, NSString (older iOS strings) and native Swift strings were completely interchangeable, as were NSArray and Swift  An NSString object initialized by converting the bytes in data into UTF-16 code units using encoding. The returned object may be different from the original receiver. Returns nil if the initialization fails for some reason (for example if data does not represent valid data for encoding).

  • { errNum = 0; retData = { address = "\U6e56\U5317\U7701\U7701\U76f4\U8f96\U53bf\U7ea7\U884c\U653f\U533a\U5212\U4ed9\U6843\U5e02"; birthday = "1989-07-10"; sex = M; }; retMsg = success; } This is the JSON that returns
  • Thanks, I just find it as I used the wrong arguments in swift, it should use %@ just as Obj-C but I used the %s instead. I fixed the error.
  • In my cace,when does not convert than makes warnning \n "Incompatible pointer types initializing ~~"
  • That's a different issue entirely. NSTaggedPointerString is about the dynamic type of the object. Your issue is about the type you have written in your source code.
  • po [NSClassFromString(@"NSTaggedPointerString") superclass] will prove your answer.
  • That sounds like something else. The issue I mentioned in the comments wouldn't apply to anything while the app is running, only when it's being compiled.
  • I found it easier to just say NSDictionary *aDict = @{[myvar valueForKey:@"item"] since the .property doesn't work well. KVO to the rescue