componentSeperatedByString in Xcode 7.3

Hi,


the string method componentSeperatedByString gives an NSArray seperated by given String...


in XCode 7.2 is this result correct my ArrayOfResult


code...

NSString *myString = @"my string has some char and special chars"];


NSArray *ArrayOfResult = [myString componentsSeparatedByString:@"specialChar"]];


but in XCode 7.3 (7D129N )the Array contain NSTaggedPointerString....

Now i want the same result an not NSTaggedPointerString...


but some components are correct as String in my Array ...????

my iPad is currently running 9.3 and 7.2 is not supported by iOS


What is NSTaggedPointerString ....


Thanks

Replies

Yes, but what is your actual problem with this situation? If NSTaggedPointerString is subclass of NSString, why do you care?


>> What is NSTaggedPointerString


A "tagged pointer" is a "fake" pointer that literally contains the data that a "real" object would contain. In the past, NSNumber objects for commonly used numbers like 0 and 1 used tagged pointers. Recently, common NSString values (about 50 different 1- and 2-character strings, IIRC) have started being represented as tagged pointers.


The Obj-C runtime has special code to detect and handle tagged pointers, so they should behave as if they were a genuine subclass of the non-tagged-pointer classes they represent.

I have the same problem with xcode 7.3


I used "componentsSeparatedByString" for extracting the file name of an URL previously converted to NSString.


The list has 5 files and in debugging mode the code works well for 4 items... one of them returns "NSTaggedPointerString" instead of the value of the string.


After comparing char by char the URLs from the rest of the items in the list, they are equal char by char excepting the file name that I want to extract.


Gotta say that the file names DO NOT have especial characters as ?,%@# etc


It's driving me crazy! I've been dealing and thinking a workaround for hours now...


Any updates?

Also having the same result if using:


tempStr = [NSString stringWithFormat:@"%@", [fileURLConvertedToString lastPathComponent]];



Only with one record of the array...

Can you post a code fragment (free-standing, not depending on some URL we don't get to see) that shows the problem?

"It seems that the problem is not comming from "componentsSeparatedByString"... First I copy two files by default into the apps documents directory, and when listing it, the problem appears: Instead of the name of the file, I get an NSTaggedPointerString. I tried replacing that file with a copy of the second one (which works well) but with the name of the first file. I get the same issue. Instead, I renamed the "conflicting" file from "TEST.TXT" to "DOCUMENTATION.TXT" and IT WORKS! It looks like there is an issue with the lenght of the file name?



NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString * documentsDirectory = [paths objectAtIndex:0];


NSMutableArray * filesInDocuments = [[NSMutableArray alloc] initWithArray:[[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:NULL] ];


When I check the value of "filesInDocuments" I get two files like:

filesInDocuments (NSArrayM*)

[0] = (NSTaggedPointerString*) 0xa009c36831c625c8

[1] = (_NSCFString*) @"SECONDFILE.TXT"


The weird thing is how is it possible that it works for one file, but not for the other one...

Got it working if the filename without extension is 6 chars or longer... (i.e. "123456.txt")

In that case, when I retrieve the file name I get an array with NSStrings.

If the file name lenght is <6 I get an array with NSTaggedPointerString and NSSting for those with file name lenght >=6


This is just amazing... any clues?

For me, it seems to be just a problem of debugger.

NSTaggedPointerString definitely is an NSString, as _NSCFString is an NSString or NSArrayM is an NSArray.


Other than the debugger cannot display the content of NSTaggedPointerString, do you have any problems when using NSTaggedPointerString as an NSString?

Hi OOper, thanks for your reply.


In fact, YES, I have problems when using NSTaggedPointerString as an NSString.

Since I populate an array with file names and then sort them, I need this array with NSStrings (for sorting by file name).

So, if I have the NSTaggedPointerString instead of the NSString I get a bunch or issues... (Can't compare a file name with xC6498hf93f8hfuhf...)


I had to rename the file name with length 6>


That will work for now but definetely I do not like the idea of file names restricctions*.

*I know it is not a restriction but I can not undestand why the code works as it should do when filenames are 6 or more characters (returning a NSString) and it does not when the file name lenght is <6 (returning a NSTaggedPointerString)...

You're missing the point. NSTaggedPointString is a NSString. Any concrete instance of NSString is actually a private subclass (e.g. _NSCFString). There are never any actual objects whose class is exactly NSString rather than a subclass.


If you're getting an error trying to sort the array of file names, show us what the error is, and the code fragment that causes it.

Maybe I need to repeat, NSTaggedPointerString is NSString. NSString is a representative of `class cluster of NSString` and NSTaggedPointerString is a member of the class cluster, as well as _NSCFString.


You can sort NSArray cotaining NSTaggedPointerString and _NSCFString and other `NSString`s.

Have your really tried to sort it?

"0xa009c36831c625c8" is not the content of the NSTaggedPointerString and just debugger does not know how to represent the content of NSTaggedPointerString.

Try:

    NSLog(@"%@", [filesInDocuments sortedArrayUsingSelector:@selector(compare:)]);

and see what the output is.