2 ms·
> 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, whi
by saagarjha 3y ago
> 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 ;)
- papereditor 3y agoKeeping my fingers crossed it will not happen. :D
- deleted 3y ago[deleted]
- deleted 3y ago[deleted]
- lapcat 3y agoOne 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!
- saagarjha 3y agoInterestingly it seems to be 10.6+ in the documentation. They backdeploy like that sometimes I guess.
- lapcat 3y agoRead the real documentation, the archive. ;-) https://developer.apple.com/library/archive/releasenotes/Foundation/RN-Foundation-older-but-post-10.8/index.html#//apple_ref/doc/uid/TP40016592 https://developer.apple.com/library/archive/releasenotes/Fou...
- saagarjha 3y agoI’m quite upset we don’t have release notes like this anymore.
- jimbokun 3y ago> I think you already know what will happen I don't know, what will happen?