On Dec 23, 2008, at 04:32, Klaus Backert wrote:

The cause of the crash is the following category, I had implemented, overriding a method of NSObject's NSKeyValueCoding category:

@interface NSObject (MyKeyValueCoding)
+ (BOOL)accessInstanceVariablesDirectly;
@end

@implementation NSObject (MyKeyValueCoding)
+ (BOOL)accessInstanceVariablesDirectly { return NO; }
@end

After having deleted this category, the application works again.

Well, there have been warnings on this mailing list about overriding methods of Cocoa categories. I did it at my own risk. Apparently it's too much stopping direct access of instance variables in key- value coding for *each* and *every* class.

Well, there are actually two very major problems with the approach you tried to use.

First, if you take away direct access to instance variables, then *all* classes that depend on it (and there are lots of them) will break. Randomly "deleting" functionality of existing classes is sure to be a bad idea. (If you want to disable the functionality in all *your* classes, the correct way would be to subclass NSObject, and then derive all your classes from this NSObject subclass.)

Second, many methods defined on NSObject (in particular, most KVC/KVO methods) are defined as categories. You can't reliably replace a method in one category by redefining the method in another category, because the order in which the categories are applied to their class is undefined. (Again, subclassing is the way to go, if you want to override a method that might be defined in a category.)


_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to