<?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: Private Methods</title>
	<atom:link href="http://iPhoneDeveloperTips.com/objective-c/private-methods.html/feed" rel="self" type="application/rss+xml" />
	<link>http://iPhoneDeveloperTips.com/objective-c/private-methods.html</link>
	<description>iOS Developer Tips, Tricks and Tutorials.</description>
	<lastBuildDate>Wed, 08 Feb 2012 06:31:16 -0600</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Pedant</title>
		<link>http://iPhoneDeveloperTips.com/objective-c/private-methods.html#comment-60602</link>
		<dc:creator>Pedant</dc:creator>
		<pubDate>Mon, 26 Sep 2011 23:31:05 +0000</pubDate>
		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=58#comment-60602</guid>
		<description>Is it just me or did most of the commenters above not understand that the warnings were a desired feature and that you were trying to show how to HIDE methods, not how to make hidden methods visible?

If you need to call methods from main(), they shouldn&#039;t be hidden in the first place.</description>
		<content:encoded><![CDATA[<p>Is it just me or did most of the commenters above not understand that the warnings were a desired feature and that you were trying to show how to HIDE methods, not how to make hidden methods visible?</p>
<p>If you need to call methods from main(), they shouldn&#8217;t be hidden in the first place.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dharmateja</title>
		<link>http://iPhoneDeveloperTips.com/objective-c/private-methods.html#comment-56160</link>
		<dc:creator>Dharmateja</dc:creator>
		<pubDate>Wed, 20 Jul 2011 14:14:45 +0000</pubDate>
		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=58#comment-56160</guid>
		<description>Great one, thank you all for helping me</description>
		<content:encoded><![CDATA[<p>Great one, thank you all for helping me</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Blajer</title>
		<link>http://iPhoneDeveloperTips.com/objective-c/private-methods.html#comment-31181</link>
		<dc:creator>Blajer</dc:creator>
		<pubDate>Thu, 11 Nov 2010 15:31:58 +0000</pubDate>
		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=58#comment-31181</guid>
		<description>The problem with categories is that, with Objective-C, you can send an object a message even if it is not defined in the interface. So declaring a method in an extension does not keep anyone from actually calling the method. With the pimpl pattern, this is impossible, since you don&#039;t have access to the object whose method you want to call.</description>
		<content:encoded><![CDATA[<p>The problem with categories is that, with Objective-C, you can send an object a message even if it is not defined in the interface. So declaring a method in an extension does not keep anyone from actually calling the method. With the pimpl pattern, this is impossible, since you don&#8217;t have access to the object whose method you want to call.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John</title>
		<link>http://iPhoneDeveloperTips.com/objective-c/private-methods.html#comment-31109</link>
		<dc:creator>John</dc:creator>
		<pubDate>Thu, 11 Nov 2010 04:24:12 +0000</pubDate>
		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=58#comment-31109</guid>
		<description>Thanks Blajer for this simple mechanism for hiding an interface. A good addition to the book of tricks. This certainly though is not a design pattern to use in order to maintain object oriented code. There&#039;s a big difference between a good OO design and making use of private methods for internal methods, and the desire to protect IP by wanting to hide the internal interface. To be fair the OP did seem to have some desire to hide &quot;private&quot; methods.

For general design I think the categories or extensions (&quot;anonymous&quot; categories) mechanism is better suited to keeping private methods separate from the public interface. This certainly would fit better when implementing and maintaining a UML design and/or keeping the internal methods separate from the object interface.</description>
		<content:encoded><![CDATA[<p>Thanks Blajer for this simple mechanism for hiding an interface. A good addition to the book of tricks. This certainly though is not a design pattern to use in order to maintain object oriented code. There&#8217;s a big difference between a good OO design and making use of private methods for internal methods, and the desire to protect IP by wanting to hide the internal interface. To be fair the OP did seem to have some desire to hide &#8220;private&#8221; methods.</p>
<p>For general design I think the categories or extensions (&#8220;anonymous&#8221; categories) mechanism is better suited to keeping private methods separate from the public interface. This certainly would fit better when implementing and maintaining a UML design and/or keeping the internal methods separate from the object interface.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joe</title>
		<link>http://iPhoneDeveloperTips.com/objective-c/private-methods.html#comment-11980</link>
		<dc:creator>Joe</dc:creator>
		<pubDate>Fri, 26 Mar 2010 17:28:51 +0000</pubDate>
		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=58#comment-11980</guid>
		<description>I&#039;m fairly new to Obj C; all of the above was useful and thought provoking. I was fine with the idea of simply defining &quot;private&quot; methods at the top of the implementation file. But I ran into an odd problem: if you have more than one arg, the compiler cries that it&#039;s looking for an &quot;;&quot; before the second arg at the point where the message is invoked:

        - (void)logMessageByTouch:(UITouch *)touch withDescriptor:(NSString *)desc {

then later a compiler error:

	[self logMessageByTouch:activeTouch withDescriptor:@&quot;touchesBegan&quot;];

The compiler is fine when I specify the method in the header, so it&#039;s not my syntax. Maybe I&#039;m missing something (I was surprised). To eliminate this compilation problem, and to avoid order of function definition dependencies (mentioned above), one can declare an @interface for a private category at the top of the .m file. Not sure if this is acceptable but it works:

@interface MyClass(private)
- (void)logMessageByTouch:(UITouch *)touch withDescriptor:(NSString *)desc;
	// other private methods here
@end
 
@implementation
...</description>
		<content:encoded><![CDATA[<p>I&#8217;m fairly new to Obj C; all of the above was useful and thought provoking. I was fine with the idea of simply defining &#8220;private&#8221; methods at the top of the implementation file. But I ran into an odd problem: if you have more than one arg, the compiler cries that it&#8217;s looking for an &#8220;;&#8221; before the second arg at the point where the message is invoked:</p>
<p>        &#8211; (void)logMessageByTouch:(UITouch *)touch withDescriptor:(NSString *)desc {</p>
<p>then later a compiler error:</p>
<p>	[self logMessageByTouch:activeTouch withDescriptor:@"touchesBegan"];</p>
<p>The compiler is fine when I specify the method in the header, so it&#8217;s not my syntax. Maybe I&#8217;m missing something (I was surprised). To eliminate this compilation problem, and to avoid order of function definition dependencies (mentioned above), one can declare an @interface for a private category at the top of the .m file. Not sure if this is acceptable but it works:</p>
<p>@interface MyClass(private)<br />
- (void)logMessageByTouch:(UITouch *)touch withDescriptor:(NSString *)desc;<br />
	// other private methods here<br />
@end</p>
<p>@implementation<br />
&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Blajer</title>
		<link>http://iPhoneDeveloperTips.com/objective-c/private-methods.html#comment-10889</link>
		<dc:creator>Blajer</dc:creator>
		<pubDate>Wed, 10 Mar 2010 23:59:40 +0000</pubDate>
		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=58#comment-10889</guid>
		<description>A very simplified example follows:

&lt;pre lang=&quot;objc&quot;&gt;
// ===========================
// = File: SomeClass.h
// = Interface for SomeClass
// ===========================
#import 

@class SomeClassImpl;
 
@interface SomeClass : Object {
  SomeClassImpl *myImpl;
} 
-(int) msg;
+(void) classMsg; 
@end
&lt;/pre&gt;

----------------------------

&lt;pre lang=&quot;objc&quot;&gt;
// ===========================
// = File: SomeClass.m
// = Implementation for SomeClass
// = NB: the pImpl class is both declared and its implementation defined here.
// ===========================

//The hidden interface goes here. These methods will not be available for the outside world.
@interface SomeClassImpl : NSObject {
}
+(void) hiddenClassMethod;
-(void) hiddenInstanceMethod; 
@end

@implementation SomeClass
-(id) init {
  if (self = [super init]) {
    myImpl = [[SomeClassImpl alloc] init];
  }
  return self;
}

-(int)msg {
  return [myImpl hiddenInstanceMethod];  //These will be perfectly hidden: no instance is leaked.
}

+(void) classMsg {
  [SomeClassImpl hiddenClassMethod];  //Well, you can&#039;t _really_ hide class methods
}

-(void) dealloc {
 [myImpl release];
 [super dealloc];
}
@end

@implementation SomeClassImpl
...
@end
&lt;/pre&gt;
</description>
		<content:encoded><![CDATA[<p>A very simplified example follows:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// ===========================</span>
<span style="color: #11740a; font-style: italic;">// = File: SomeClass.h</span>
<span style="color: #11740a; font-style: italic;">// = Interface for SomeClass</span>
<span style="color: #11740a; font-style: italic;">// ===========================</span>
<span style="color: #6e371a;">#import </span>
&nbsp;
<span style="color: #a61390;">@class</span> SomeClassImpl;
&nbsp;
<span style="color: #a61390;">@interface</span> SomeClass <span style="color: #002200;">:</span> Object <span style="color: #002200;">&#123;</span>
  SomeClassImpl <span style="color: #002200;">*</span>myImpl;
<span style="color: #002200;">&#125;</span> 
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span> msg;
<span style="color: #002200;">+</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> classMsg; 
<span style="color: #a61390;">@end</span></pre></div></div>

<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// ===========================</span>
<span style="color: #11740a; font-style: italic;">// = File: SomeClass.m</span>
<span style="color: #11740a; font-style: italic;">// = Implementation for SomeClass</span>
<span style="color: #11740a; font-style: italic;">// = NB: the pImpl class is both declared and its implementation defined here.</span>
<span style="color: #11740a; font-style: italic;">// ===========================</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">//The hidden interface goes here. These methods will not be available for the outside world.</span>
<span style="color: #a61390;">@interface</span> SomeClassImpl <span style="color: #002200;">:</span> <span style="color: #400080;">NSObject</span> <span style="color: #002200;">&#123;</span>
<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">+</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> hiddenClassMethod;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> hiddenInstanceMethod; 
<span style="color: #a61390;">@end</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> SomeClass
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> init <span style="color: #002200;">&#123;</span>
  <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
    myImpl <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>SomeClassImpl alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#125;</span>
  <span style="color: #a61390;">return</span> self;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>msg <span style="color: #002200;">&#123;</span>
  <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>myImpl hiddenInstanceMethod<span style="color: #002200;">&#93;</span>;  <span style="color: #11740a; font-style: italic;">//These will be perfectly hidden: no instance is leaked.</span>
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">+</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> classMsg <span style="color: #002200;">&#123;</span>
  <span style="color: #002200;">&#91;</span>SomeClassImpl hiddenClassMethod<span style="color: #002200;">&#93;</span>;  <span style="color: #11740a; font-style: italic;">//Well, you can't _really_ hide class methods</span>
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> dealloc <span style="color: #002200;">&#123;</span>
 <span style="color: #002200;">&#91;</span>myImpl release<span style="color: #002200;">&#93;</span>;
 <span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@end</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> SomeClassImpl
...
<span style="color: #a61390;">@end</span></pre></div></div>

]]></content:encoded>
	</item>
	<item>
		<title>By: John Muchow</title>
		<link>http://iPhoneDeveloperTips.com/objective-c/private-methods.html#comment-10887</link>
		<dc:creator>John Muchow</dc:creator>
		<pubDate>Wed, 10 Mar 2010 23:45:34 +0000</pubDate>
		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=58#comment-10887</guid>
		<description>Thanks Blajer, any code example(s) you can provide to add some additional insight?</description>
		<content:encoded><![CDATA[<p>Thanks Blajer, any code example(s) you can provide to add some additional insight?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Blajer</title>
		<link>http://iPhoneDeveloperTips.com/objective-c/private-methods.html#comment-10886</link>
		<dc:creator>Blajer</dc:creator>
		<pubDate>Wed, 10 Mar 2010 23:40:27 +0000</pubDate>
		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=58#comment-10886</guid>
		<description>The issue of private methods is best solved with the Pointer-to-Implementation pattern. The implementation class may have whatever methods, but its instance (and even the methods it exposes) is kept in the private fields and is not accessible from the outside world.</description>
		<content:encoded><![CDATA[<p>The issue of private methods is best solved with the Pointer-to-Implementation pattern. The implementation class may have whatever methods, but its instance (and even the methods it exposes) is kept in the private fields and is not accessible from the outside world.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://iPhoneDeveloperTips.com/objective-c/private-methods.html#comment-3056</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Tue, 16 Jun 2009 04:09:49 +0000</pubDate>
		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=58#comment-3056</guid>
		<description>The method which I read in the O&#039;Reilly &#039;Learning Cocoa&#039; book - which in my opinion is slightly cleaner:

1) Declare the private methods in a separate .h file (with a file name like &quot;SomeClassPrivate.h&quot;).
2) Tag this interface with a (private) category.
3) Import both the SomeClass.h &amp; SomeClassPrivate.h into your implementation .m file

The benefits are:
Increased separation of code - the private interface is apart from the public (still)
The private methods can be placed anywhere in your implementation (the whole reason for header files in the first place).</description>
		<content:encoded><![CDATA[<p>The method which I read in the O&#8217;Reilly &#8216;Learning Cocoa&#8217; book &#8211; which in my opinion is slightly cleaner:</p>
<p>1) Declare the private methods in a separate .h file (with a file name like &#8220;SomeClassPrivate.h&#8221;).<br />
2) Tag this interface with a (private) category.<br />
3) Import both the SomeClass.h &amp; SomeClassPrivate.h into your implementation .m file</p>
<p>The benefits are:<br />
Increased separation of code &#8211; the private interface is apart from the public (still)<br />
The private methods can be placed anywhere in your implementation (the whole reason for header files in the first place).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rodney</title>
		<link>http://iPhoneDeveloperTips.com/objective-c/private-methods.html#comment-14</link>
		<dc:creator>Rodney</dc:creator>
		<pubDate>Sun, 17 Aug 2008 00:36:53 +0000</pubDate>
		<guid isPermaLink="false">http://iPhoneDeveloperTips.com/?p=58#comment-14</guid>
		<description>This is a fantastic resource John!  This post in particular was really helpful for an &quot;old&quot; Java developer like myself.  Getting my head around the crazy syntax of ObjectiveC is one of the biggest hurdles I have learning to develop for iPhone.  Keep up the great work!</description>
		<content:encoded><![CDATA[<p>This is a fantastic resource John!  This post in particular was really helpful for an &#8220;old&#8221; Java developer like myself.  Getting my head around the crazy syntax of ObjectiveC is one of the biggest hurdles I have learning to develop for iPhone.  Keep up the great work!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

