<?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>An Experiment in Bloggery &#187; objc</title>
	<atom:link href="http://kevin.sb.org/tag/objc/feed/" rel="self" type="application/rss+xml" />
	<link>http://kevin.sb.org</link>
	<description>The occasional view into my life</description>
	<lastBuildDate>Fri, 09 Sep 2011 00:19:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Method Swizzling reimplemented</title>
		<link>http://kevin.sb.org/2006/12/30/method-swizzling-reimplemented/</link>
		<comments>http://kevin.sb.org/2006/12/30/method-swizzling-reimplemented/#comments</comments>
		<pubDate>Sun, 31 Dec 2006 00:36:00 +0000</pubDate>
		<dc:creator>Kevin Ballard</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Method Swizzling]]></category>
		<category><![CDATA[objc]]></category>

		<guid isPermaLink="false">http://755af07c-abcf-4e90-a7ea-729102b32de8</guid>
		<description><![CDATA[Update: This code was written pre-Leopard, and as such doesn&#8217;t run under ObjC 2. See JRSwizzle for an updated version that runs under Leopard and Snow Leopard. Method Swizzling is one common technique of people writing hacks, such as Safari Plugins. Unfortunately, it&#8217;s always suffered from a flaw, wherein swizzling inherited methods affects all classes [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update</strong>: This code was written pre-Leopard, and as such doesn&#8217;t run under ObjC 2. See <a href="http://github.com/rentzsch/jrswizzle">JRSwizzle</a> for an updated version that runs under Leopard and Snow Leopard.</p>

<p>Method Swizzling is one common technique of people writing hacks, such as <a href="http://www.pimpmysafari.com" title="Pimp My Safari">Safari Plugins</a>.
Unfortunately, it&#8217;s always suffered from a flaw, wherein swizzling inherited methods affects all
classes which inherit that method (including the base class), rather than the intended subclass.
This problem is discussed on the <a href="http://www.cocoadev.com/index.pl?MethodSwizzling">CocoaDev Method Swizzling</a> page.</p>

<p>As part of writing <a href="http://kevin.sb.org/articles/2006/12/27/yubnubsearch-simbl-bundle">YubNubSearch</a>, I decided to solve this problem.</p>

<p>First I looked into dynamic subclass generation + posing. Unfortunately, this has a big problem. In
this technique, calling the original implementation would naturally be done through a <code>[super foo]</code> call.
Unfortunately, when the compiler sees <code>super</code>, it hardcodes a reference to the superclass at which to
start the search. This means you cannot write this code in, say, a category on NSObject, then pull up the IMP
into a dynamically-generated subclass and have it work. So that throws out that idea.</p>

<p>The other idea I had, which I eventually went with, was to copy inherited methods into the subclass that you
wish to swizzle, before swizzling. It turned out to be fairly easy, and still has the same semantics as the old,
flawed technique for calling the original implementation.</p>

<p>You can download my implementation <a href="http://www.tildesoft.com/Files/MethodSwizzle.tgz">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://kevin.sb.org/2006/12/30/method-swizzling-reimplemented/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
