{"id":4466,"date":"2014-03-30T11:18:01","date_gmt":"2014-03-30T11:18:01","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/using-super-in-an-objective-c-category-collection-of-common-programming-errors\/"},"modified":"2014-03-30T11:18:01","modified_gmt":"2014-03-30T11:18:01","slug":"using-super-in-an-objective-c-category-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/using-super-in-an-objective-c-category-collection-of-common-programming-errors\/","title":{"rendered":"Using Super in an Objective C Category?-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;d like to override a method in an Objective C class that I don&#8217;t have the source to.<\/p>\n<p>I&#8217;ve looked into it, and it appears that Categories should allow me to do this, but I&#8217;d like to use the result of the old method in my new method, using super to get the old methods result.<\/p>\n<p>Whenever I try this though, my method gets called, but &#8220;super&#8221; is nil&#8230; Any idea why? I&#8217;m doing iPhone development with the XCode 2.2 SDK. I&#8217;m definitely working with an instance of a class, and the method of the class is an instance method.<\/p>\n<pre><code>@implementation SampleClass (filePathResolver)\n-(NSString*) fullPathFromRelativePath:(NSString*) relPath\n{\n    NSString *result = [super fullPathFromRelativePath: relPath];\n\n  ... do some stuff with the old result\n\n    return result;\n}\n<\/code><\/pre>\n<p>Note and clarification: From what I can see in the Apple Docs, it appears to me that this should be allowed?<\/p>\n<blockquote>\n<p>Categories docs at developer.apple.com: 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>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;d like to override a method in an Objective C class that I don&#8217;t have the source to. I&#8217;ve looked into it, and it appears that Categories should allow me to do this, but I&#8217;d like to use the result of the old method in my new method, using super to get the old methods [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4466","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4466","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4466"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4466\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4466"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4466"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4466"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}