0
votes

I have an app that I sell in the Mac marketplace and this app has been running without a hitch -- until customers started running it under Mavericks.

What it boils down to are exceptions like this that I'm getting back from customers:

11/7/13 8:54:17.841 AM MyApp[65256]: -[Property watts Per Square MeterStringValue]: unrecognized selector sent to instance 0x7fa66c80a760

Now, it's obvious that "watts Per Square MeterStringValue" is not a valid selector, but let me explain.

I have a category on NSString that has a series of methods which do different things like remove spaces from strings, or set the first character of a string to lowercase, etc. This category exists in a framework that I embed in my app.

One particular method in that category is "bindString" which converts a string to a bindable, camel case string. So:

[@"This is a Funky String" bindString]

would yield:

"thisIsAFunkyString"

What appears to be happening in my app under Mavericks is that the category method is not being always called, even though it is referenced in the source. This behavior is purely random. While the app is running, sometimes it will be called, and sometimes not. When it's not, exceptions like the one above occur.

This happens ONLY under Mavericks. The same binary works flawlessly under Mountain Lion and Lion.

Now I'm wondering why this is. Is it an Obj-C runtime issue under Mavericks? Is it an Xcode 5.0.1 compiler issue? I don't know, but it's just plain weird, and it's driving me up the wall.

I've tried just about everything. The next thing I'm going to try is to yank the category .m and .h out of the framework and put it directly into the app project.

Has anyone seen anything like this under Mavericks?

1
A test case the reproduces the problem would be nice. Or at least an example of how you use the category?Taum

1 Answers

2
votes

Hanging categories off NSString is generally a bad idea. Especially when your method names aren't prefixed. If you really have a method named bindString in a category on NSString, you may be colliding with a method provided in a category somewhere in the Apple frameworks. When two categories implement the same selector, which one "wins" is indeterminate.

Keep in mind that NSString is a class cluster. Thus, if the method is colliding with a method on a subclass, you'll also see weird behavior in that your category's method may not always be invoked.

At the very least, put a prefix on all of the methods in categories on system classes. Better yet, don't extend the system classes; put your methods in their own class.