Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Categories in Objective-C are a way to add new methods to any existing class, including framework classes (categories can also be used to replace methods, which is both powerful and scary ). I use them to harmonize the API. So if a method in UITextField is called text and in NSTextField it is called stringValue I can add a stringValue method to UITextField that calls text (or vice versa).

> By the way, I also use categories to shorten long framework methods. The underscore at the end helps to avoid clashes with public or private methods that Apple might decide to add in the future.

I think you already know what will happen if Apple adds a method (public or private) called text to NSTextField or stringValue to UITextField in the future ;)



One problem in the past was -[NSArray firstObject], which many developers used as a category method, with differing implementations. Apple added it to the Mac OS X 10.9 SDK but actually implemented the method silently in 10.6!


Interestingly it seems to be 10.6+ in the documentation. They backdeploy like that sometimes I guess.


Read the real documentation, the archive. ;-) https://developer.apple.com/library/archive/releasenotes/Fou...


I’m quite upset we don’t have release notes like this anymore.


> I think you already know what will happen

I don't know, what will happen?


One of the implementations will get used. If they differ this is likely to cause at least one caller to be very upset.


So..."undefined behavior"?


Yes.


Keeping my fingers crossed it will not happen. :D




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: