<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Categories</title>
	<atom:link href="http://iPhoneDeveloperTips.com/objective-c/categories.html/feed" rel="self" type="application/rss+xml" />
	<link>http://iPhoneDeveloperTips.com/objective-c/categories.html</link>
	<description>Tips and Tricks for iPhone developers</description>
	<lastBuildDate>Thu, 29 Jul 2010 23:00:59 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Nick D</title>
		<link>http://iPhoneDeveloperTips.com/objective-c/categories.html/comment-page-1#comment-16258</link>
		<dc:creator>Nick D</dc:creator>
		<pubDate>Tue, 01 Jun 2010 05:51:04 +0000</pubDate>
		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=56#comment-16258</guid>
		<description>@Leifur 

The Apple documentation actually states that it&#039;s a bad idea to use categories to override instance or class methods: http://developer.apple.com/mac/library/documentation/cocoa/conceptual/objectivec/articles/occategories.html

The relevant bit for you is the first bullet point in this section:

&quot;Although the language currently allows you to use a category to override methods the class inherits, or even methods declared in the class interface, you are strongly discouraged from using this functionality. A category is not a substitute for a subclass. There are several significant shortcomings:

    *      When a category overrides an inherited method, the method in the category can, as usual, invoke the inherited implementation via a message to super. However, if a category overrides a method that already existed in the category&#039;s class, there is no way to invoke the original implementation.

    *      A category cannot reliably override methods declared in another category of the same class.

      This issue is of particular significance since many of the Cocoa classes are implemented using categories. A framework-defined method you try to override may itself have been implemented in a category, and so which implementation takes precedence is not defined.

    *      The very presence of some methods may cause behavior changes across all frameworks. For example, if you add an implementation of windowWillClose: to NSObject, this will cause all window delegates to respond to that method and may modify the behavior of all instances of NSWindow instances. This may cause mysterious changes in behavior and can lead to crashes.&quot;

...hope that helps!
Nick</description>
		<content:encoded><![CDATA[<p>@Leifur </p>
<p>The Apple documentation actually states that it&#8217;s a bad idea to use categories to override instance or class methods: <a href="http://developer.apple.com/mac/library/documentation/cocoa/conceptual/objectivec/articles/occategories.html" rel="nofollow">http://developer.apple.com/mac/library/documentation/cocoa/conceptual/objectivec/articles/occategories.html</a></p>
<p>The relevant bit for you is the first bullet point in this section:</p>
<p>&#8220;Although the language currently allows you to use a category to override methods the class inherits, or even methods declared in the class interface, you are strongly discouraged from using this functionality. A category is not a substitute for a subclass. There are several significant shortcomings:</p>
<p>    *      When a category overrides an inherited method, the method in the category can, as usual, invoke the inherited implementation via a message to super. However, if a category overrides a method that already existed in the category&#8217;s class, there is no way to invoke the original implementation.</p>
<p>    *      A category cannot reliably override methods declared in another category of the same class.</p>
<p>      This issue is of particular significance since many of the Cocoa classes are implemented using categories. A framework-defined method you try to override may itself have been implemented in a category, and so which implementation takes precedence is not defined.</p>
<p>    *      The very presence of some methods may cause behavior changes across all frameworks. For example, if you add an implementation of windowWillClose: to NSObject, this will cause all window delegates to respond to that method and may modify the behavior of all instances of NSWindow instances. This may cause mysterious changes in behavior and can lead to crashes.&#8221;</p>
<p>&#8230;hope that helps!<br />
Nick</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sebastian</title>
		<link>http://iPhoneDeveloperTips.com/objective-c/categories.html/comment-page-1#comment-15655</link>
		<dc:creator>Sebastian</dc:creator>
		<pubDate>Fri, 21 May 2010 23:25:00 +0000</pubDate>
		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=56#comment-15655</guid>
		<description>Thank you! 
With this perfect explanation i just managed my write my first category that saves me typing when loading images in a imageview when &quot;imagenamed&quot; would clutter the ram / cache.
Thank you! Thank you! Thank you!</description>
		<content:encoded><![CDATA[<p>Thank you!<br />
With this perfect explanation i just managed my write my first category that saves me typing when loading images in a imageview when &#8220;imagenamed&#8221; would clutter the ram / cache.<br />
Thank you! Thank you! Thank you!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sascha Hameister</title>
		<link>http://iPhoneDeveloperTips.com/objective-c/categories.html/comment-page-1#comment-12125</link>
		<dc:creator>Sascha Hameister</dc:creator>
		<pubDate>Sun, 28 Mar 2010 06:04:16 +0000</pubDate>
		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=56#comment-12125</guid>
		<description>Hey John,

I just a very efficient way to reverse a string and started with your lines of codes. Here is what I came up at the end. Hope this will help for some people. :-)

@implementation NSString (reverse)
- (NSString *) reverseString {
	NSMutableString *reversedStr;
	int len = [self length];
	
	// Auto released string
	reversedStr = [NSMutableString stringWithCapacity:len];     
	
	while (len--) {
		[reversedStr appendFormat:@&quot;%C&quot;, [self characterAtIndex:len]];
	}
	
	return reversedStr;
}</description>
		<content:encoded><![CDATA[<p>Hey John,</p>
<p>I just a very efficient way to reverse a string and started with your lines of codes. Here is what I came up at the end. Hope this will help for some people. :-)</p>
<p>@implementation NSString (reverse)<br />
- (NSString *) reverseString {<br />
	NSMutableString *reversedStr;<br />
	int len = [self length];</p>
<p>	// Auto released string<br />
	reversedStr = [NSMutableString stringWithCapacity:len];     </p>
<p>	while (len&#8211;) {<br />
		[reversedStr appendFormat:@"%C", [self characterAtIndex:len]];<br />
	}</p>
<p>	return reversedStr;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Sanchez</title>
		<link>http://iPhoneDeveloperTips.com/objective-c/categories.html/comment-page-1#comment-8875</link>
		<dc:creator>Mark Sanchez</dc:creator>
		<pubDate>Fri, 22 Jan 2010 02:17:45 +0000</pubDate>
		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=56#comment-8875</guid>
		<description>F.Y.I. Posible Error with naming classes and use of categories.

I have used categories to breakup a class into multiple files with no problems in the past.  I tried to do the same with a class name (&quot;Game_2ViewController+Animation.h&quot;) that had an underscore character and the methods and functions defined within the subcategory class file could not be called by the program.  I simply made a new subcategory class file and used no underscore character (&quot;Game2ViewController+Animation.h&quot;) and the problem went away?</description>
		<content:encoded><![CDATA[<p>F.Y.I. Posible Error with naming classes and use of categories.</p>
<p>I have used categories to breakup a class into multiple files with no problems in the past.  I tried to do the same with a class name (&#8220;Game_2ViewController+Animation.h&#8221;) that had an underscore character and the methods and functions defined within the subcategory class file could not be called by the program.  I simply made a new subcategory class file and used no underscore character (&#8220;Game2ViewController+Animation.h&#8221;) and the problem went away?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Hohle</title>
		<link>http://iPhoneDeveloperTips.com/objective-c/categories.html/comment-page-1#comment-8635</link>
		<dc:creator>Jonathan Hohle</dc:creator>
		<pubDate>Tue, 12 Jan 2010 16:13:01 +0000</pubDate>
		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=56#comment-8635</guid>
		<description>@Leifur Bjorn when you shadow a method with a category, you lose access to the original method. You can think of categories like adding items to a class or instance method dictionary. If you add a value for a key that already exists, you&#039;ll overwrite the existing value. (There are ways to get around this at runtime by saving the pointer to the old method, but not at compile time.)

To access the original method you must subclass.</description>
		<content:encoded><![CDATA[<p>@Leifur Bjorn when you shadow a method with a category, you lose access to the original method. You can think of categories like adding items to a class or instance method dictionary. If you add a value for a key that already exists, you&#8217;ll overwrite the existing value. (There are ways to get around this at runtime by saving the pointer to the old method, but not at compile time.)</p>
<p>To access the original method you must subclass.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Muchow</title>
		<link>http://iPhoneDeveloperTips.com/objective-c/categories.html/comment-page-1#comment-8632</link>
		<dc:creator>John Muchow</dc:creator>
		<pubDate>Tue, 12 Jan 2010 14:33:35 +0000</pubDate>
		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=56#comment-8632</guid>
		<description>pramod, I would imagine you could use categories with ui objects as they as simply another object.</description>
		<content:encoded><![CDATA[<p>pramod, I would imagine you could use categories with ui objects as they as simply another object.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pramod</title>
		<link>http://iPhoneDeveloperTips.com/objective-c/categories.html/comment-page-1#comment-8624</link>
		<dc:creator>pramod</dc:creator>
		<pubDate>Tue, 12 Jan 2010 07:32:48 +0000</pubDate>
		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=56#comment-8624</guid>
		<description>Can cateogeory be applied to ui objects i mean (view, tabbars and navigation bars etc..)</description>
		<content:encoded><![CDATA[<p>Can cateogeory be applied to ui objects i mean (view, tabbars and navigation bars etc..)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Leifur Bjorn</title>
		<link>http://iPhoneDeveloperTips.com/objective-c/categories.html/comment-page-1#comment-7642</link>
		<dc:creator>Leifur Bjorn</dc:creator>
		<pubDate>Tue, 08 Dec 2009 03:37:49 +0000</pubDate>
		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=56#comment-7642</guid>
		<description>Great post John,

I tried to use the same method to have a category overwrite viewDidLoad of a UIViewController class.  But the problem is that the category implementation is unable to call the [super viewDidLoad method].  The compiler gives me a warning that the viewDidLoad method is not part of UIResponder.  Strange.

Here is the category code

// Header
@interface UIViewController (UIViewController_TestingCategory) 
  - (void) viewDidLoad;

@end


// Implementation file

#import &quot;UIViewController+TestingCategory.h&quot;

@implementation UIViewController (UIViewController_TestingCategory)

- (void)viewDidLoad {
    [super viewDidLoad];

   // Do my own special behavior of view did load
  ....
}

-&gt; The compiler gives me the warning on [super viewDidLoad] and of course things crash.

Do I have to revert to subclassic.  I would like to use categories so I don&#039;t have to change my view controllers to inherit from my own UIViewController class.

Thanks,
Leifur</description>
		<content:encoded><![CDATA[<p>Great post John,</p>
<p>I tried to use the same method to have a category overwrite viewDidLoad of a UIViewController class.  But the problem is that the category implementation is unable to call the [super viewDidLoad method].  The compiler gives me a warning that the viewDidLoad method is not part of UIResponder.  Strange.</p>
<p>Here is the category code</p>
<p>// Header<br />
@interface UIViewController (UIViewController_TestingCategory)<br />
  &#8211; (void) viewDidLoad;</p>
<p>@end</p>
<p>// Implementation file</p>
<p>#import &#8220;UIViewController+TestingCategory.h&#8221;</p>
<p>@implementation UIViewController (UIViewController_TestingCategory)</p>
<p>- (void)viewDidLoad {<br />
    [super viewDidLoad];</p>
<p>   // Do my own special behavior of view did load<br />
  &#8230;.<br />
}</p>
<p>-&gt; The compiler gives me the warning on [super viewDidLoad] and of course things crash.</p>
<p>Do I have to revert to subclassic.  I would like to use categories so I don&#8217;t have to change my view controllers to inherit from my own UIViewController class.</p>
<p>Thanks,<br />
Leifur</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Muchow</title>
		<link>http://iPhoneDeveloperTips.com/objective-c/categories.html/comment-page-1#comment-4296</link>
		<dc:creator>John Muchow</dc:creator>
		<pubDate>Thu, 13 Aug 2009 21:29:45 +0000</pubDate>
		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=56#comment-4296</guid>
		<description>nir, unfortunately, you cannot add instance variables to a class.</description>
		<content:encoded><![CDATA[<p>nir, unfortunately, you cannot add instance variables to a class.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nir</title>
		<link>http://iPhoneDeveloperTips.com/objective-c/categories.html/comment-page-1#comment-4295</link>
		<dc:creator>nir</dc:creator>
		<pubDate>Thu, 13 Aug 2009 21:26:05 +0000</pubDate>
		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=56#comment-4295</guid>
		<description>Thanks, very clear and detailed explanation. Can I add new member variables (it seems i cannot, but you might have some tip).</description>
		<content:encoded><![CDATA[<p>Thanks, very clear and detailed explanation. Can I add new member variables (it seems i cannot, but you might have some tip).</p>
]]></content:encoded>
	</item>
</channel>
</rss>
