<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Apfelsaft &#187; cocoa</title>
	<atom:link href="http://www.deelen.de/tag/cocoa/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.deelen.de</link>
	<description>Yet another Mac developer blog</description>
	<lastBuildDate>Sun, 03 Mar 2024 08:13:55 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Cocoa Animation Proxy &#8220;woes&#8221;</title>
		<link>http://www.deelen.de/2010/02/cocoa-animation-proxies-woes/</link>
		<comments>http://www.deelen.de/2010/02/cocoa-animation-proxies-woes/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 14:24:45 +0000</pubDate>
		<dc:creator>Joachim</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[animator]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[setHidden]]></category>

		<guid isPermaLink="false">http://www.deelen.de/?p=114</guid>
		<description><![CDATA[Both, NSWindow and NSView offer a convenient way to add animation to your UI by the use of animation proxies. But there are some &#8220;woes&#8221; you have to keep in mind.

E.g. if you want to switch the visibility state you normally use:

[aView setHidden:YES]; // Hide the view
// very important code....
[aView setHidden:NO]; // Un-Hide the view

To [...]]]></description>
			<content:encoded><![CDATA[<p>Both, NSWindow and NSView offer a convenient way to add animation to your UI by the use of animation proxies. But there are some &#8220;woes&#8221; you have to keep in mind.<br />
<span id="more-114"></span><br />
E.g. if you want to switch the visibility state you normally use:</p>
<pre class="brush: objc;">
[aView setHidden:YES]; // Hide the view
// very important code....
[aView setHidden:NO]; // Un-Hide the view
</pre>
<p>To do the same thing with a short and smooth animation, you just have to change the above code to the following:</p>
<pre class="brush: objc;">
[[aView animator] setHidden:YES]; // Hide the view with animation
// very important code....
[[aView animator] setHidden:NO]; // Un-Hide the view with animation
</pre>
<p>(For some animations, like subview transitions, <kbd>aView</kbd> has to be layer-backed which can be accomplished with a call to <kbd>[aView setWantsLayer:YES];</kbd>)</p>
<p>So far so good. But what, if <kbd>aView</kbd> is a custom subclass of NSView, NSBox or whatsoever?</p>
<p>Normally, this is not a problem, since the object returned by <kbd>[aView animator]</kbd> is a proxy object for the original object and can be treated as if it was the original object itself.</p>
<p>But, there is a difference! If you call <kbd>setHidden:YES</kbd> on the original object, it gets called, regardless of the actual &#8220;hidden-state&#8221; of the view. If you call it on the proxy-object, it gets called only, if the value really changes. So calling <kbd>setHidden:YES</kbd> on an animator-proxy, which original-object is already hidden, has no effect at all.</p>
<p>This behavior can be ignored, as long as you do not overwrite any of the methods that change animateable properties, like <kbd>setHidden:</kbd>. But if you do, keep in mind, that your overwritten method may not be called while using the animator-proxy. In some cases, were you depend upon the fact, that your method gets always called, this can be a problem e.g. if you always want to do something in your setter, regardless of what the actual state or value is.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.deelen.de/2010/02/cocoa-animation-proxies-woes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>+ (void)initialize called only once?</title>
		<link>http://www.deelen.de/2010/02/voidinitialize-called-only-once/</link>
		<comments>http://www.deelen.de/2010/02/voidinitialize-called-only-once/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 15:20:02 +0000</pubDate>
		<dc:creator>Joachim</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[bindings]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[initialize]]></category>
		<category><![CDATA[objectivec]]></category>
		<category><![CDATA[subclass]]></category>

		<guid isPermaLink="false">http://www.deelen.de/?p=65</guid>
		<description><![CDATA[To make a long story short: The answer is no!
Even if you don&#8217;t subclass, there are side effects you&#8217;d never thought possible.

A few days ago I ran into a tricky problem while working on my iTunes-Controller Playwatch. After spending some time debugging I came to the conclusion that only multiple calls to the &#8220;initialize-method&#8221; could [...]]]></description>
			<content:encoded><![CDATA[<p>To make a long story short: The answer is no!</p>
<p>Even if <strong>you</strong> don&#8217;t subclass, there are side effects you&#8217;d never thought possible.<br />
<span id="more-65"></span></p>
<p>A few days ago I ran into a tricky problem while working on my iTunes-Controller Playwatch. After spending some time debugging I came to the conclusion that only multiple calls to the &#8220;initialize-method&#8221; could cause the problem.</p>
<p>Apple’s documentation states, that initialize is called only once. If you create subclasses of your class, initialize gets called for each subclass. If the subclass does not implement it, the call is forwarded to the superclass. This is the exception to the rule. If you subclass, initialize of your superclass maybe called more than once. To avoid double initialization, the documentation recommends to check the class-instance and do initialization only if it’s the correct one.</p>
<p>Here&#8217;s the code:</p>
<pre class="brush: objc;">
@implementation MyClass
+ (void)initialize
{
	if(self == [MyClass class]) {
		// Do initialization here....
	}
}
@end
</pre>
<p>Since I did not have any subclasses, I thought I could run without this check. Far wrong! To find out what was going on, I set a breakpoint at initialize. The debugger stopped once, and a second time. Even with no subclasses. How could that be? A look at the Variable “self” shed some light on this miracle.</p>
<p>The first time the stack and the variable looked like this: (Click on the images to see full resolution)</p>
<p><a href="http://www.deelen.de/wordpress/wp-content/uploads/2010/02/Bildschirmfoto-2010-02-15-um-14.56.20.png"><img src="http://www.deelen.de/wordpress/wp-content/uploads/2010/02/Bildschirmfoto-2010-02-15-um-14.56.20.png" alt="" title="initialized called the first time" width="542" height="330" class="alignnone size-full wp-image-83" /></a></p>
<p>The second time the result was as follows:</p>
<p><a href="http://www.deelen.de/wordpress/wp-content/uploads/2010/02/Bildschirmfoto-2010-02-15-um-14.57.04.png"><img src="http://www.deelen.de/wordpress/wp-content/uploads/2010/02/Bildschirmfoto-2010-02-15-um-14.57.04.png" alt="" title="initialize called a second time" width="556" height="328" class="alignnone size-full wp-image-84" /></a></p>
<p>The first call to initialize is on the class “PWCoverArtAndTracks”. The second one is on the class “NSKVONotifying_PWCoverArtAndTracks”.</p>
<p>All right! The AppKit did create a subclass because I use the tracks-array of “PWCoverArtAndTracks” as the content binding for a NSCollectionView. As you can see at the picture below.</p>
<p><a href="http://www.deelen.de/wordpress/wp-content/uploads/2010/02/Bildschirmfoto-2010-02-15-um-15.18.45.png"><img src="http://www.deelen.de/wordpress/wp-content/uploads/2010/02/Bildschirmfoto-2010-02-15-um-15.18.45.png" alt="" title="Class used for binding in IB" width="968" height="478" class="alignnone size-full wp-image-64" /></a></p>
<p>This is an implementation detail of CocoaBindings. I can remember reading something about this detail in the Apple Docs. But that remembrance was almost vanished at the time I wrote the initialize method.</p>
<p>Here’s my advice: Always check the class within initialize. Even if you don’t have subclasses.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.deelen.de/2010/02/voidinitialize-called-only-once/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
