Running in XCode different than running in Catalina?

I found a bug in XCode 11.6 and/or Catalina 10.15.6. I have a work around listed below, but wondered if this a general problem that should cause concern?

In brief, I extended NSString class in Objective C with some personal convenience methods. Here is simplified header for "MyStringAdditiotions" showing just one convenience method:

Code Block
@interface NSString (MyStringAdditions)
- (NSString *)unquote;
@end

The one method is code I wrote a long time ago to remove white space and then if needed remove quotes on a string using such code as

Code Block
NSString *myString = " \"quoted text\"";
NSString *uqString = [myString unquote];

to return just uqString = quoted text.

The code itself is irrelevant and I am sure it is correct, but I got reports from users that it stopped working in Catalina. I was unable to reproduce their problems until I noticed that when I compile and run my app in XCode it works fine, but if I quit XCode and launch the app just compiled in XCode directly in Catalina, in runs differently and quotes and not removed. I tried NSLog() message in my unquote method. Those messages appear when running in XCode, but not when running in Catalina.

In summary, Catalina is not calling my convenience method. It is not, however, universal. I have lots of other methods in "MyStringAdditions" that are called correctly in Catalina. So far it appears only to be "unquote", but I cannot be sure and I don't know why the problem (hence the concern).

Two ways to fix it are to rename the method (e.g., to myUnquote) or to avoid using Objective C methods to extend a class (i.e., move the code to some other class). I thought maybe it was a naming conflict, but a search of developer documentation does not return any results for "unquote" in Objective C for NSString. Furthermore, if there was a conflict, it should affect running in XCode the same as running in Catalina (or at least give a warning of a conflict).

I thought maybe it was a naming conflict, but a search of developer
documentation does not return any results for -unquote in Objective
C for NSString. Furthermore, if there was a conflict, it should
affect running in XCode the same as running in Catalina (or at least
give a warning of a conflict).

Unfortunately both of these suppositions are wrong.

In Objective-C the methods on a class exist within a single namespace. If library A implements -unquote and library B implements -unquote, you have a conflict. These implementations can come from any library loaded in your process. You’ve ruled out a public -unquote system method, but there’s a possibility of a private system method, or another implementation from some third-party library loaded in your process.

Additionally, if you have a conflict like this the actual implementation that gets called is not defined. It’s completely possible that you’ll get different implementations when run in Xcode then when run from Finder.

For this reason I recommend that you either avoid categories like this completely or you use a much-more-likely-to-be-unique method name. Or use Swift, where we finally resolved this problem (-:

Oh, and there’s a handy dandy Q\&A that discusses this stuff in more detail, namely QA1908 Finding and Fixing Category Method Name Clashes.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"

For this reason I recommend that you either avoid categories like this completely

Well that's just peachy.

Or use Swift, where we finally resolved this problem (-:

Well I've seen some hints of future C++ support in Swift.

In summary, Catalina is not calling my convenience method. It is not, however, universal. I have lots of other methods in "MyStringAdditions" that are called correctly in Catalina. So far it appears only to be "unquote", but I cannot be sure and I don't know why the problem (hence the concern).

After recovering from my Objective-C exception un-safe policy flashback, I checked my own code using the OBJC_PRINT_REPLACED_METHODS environment variable. There is definitely an "-[NSString unquote]" defined in category CALExtensions in the CalDAV framework.

Running in XCode different than running in Catalina?
 
 
Q