{"id":5258,"date":"2014-03-30T20:03:13","date_gmt":"2014-03-30T20:03:13","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/initwithcoder-getting-called-by-nib-nscoding-collection-of-common-programming-errors\/"},"modified":"2014-03-30T20:03:13","modified_gmt":"2014-03-30T20:03:13","slug":"initwithcoder-getting-called-by-nib-nscoding-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/initwithcoder-getting-called-by-nib-nscoding-collection-of-common-programming-errors\/","title":{"rendered":"initWithCoder: getting called by nib &amp; NSCoding!-Collection of common programming errors"},"content":{"rendered":"<p>Don&#8217;t forget to put the nil check in your init methods. E.g. the method you posted would be more correct if you wrote it as:<\/p>\n<pre><code>- (id)initWithCoder:(NSCoder *)coder {\n    if (self = [super initWithCoder:coder]) {\n        [[self mapView] addAnnotations:[[coder decodeObjectForKey:@\"Annotations\"] retain]];\n    } \n    return self;\n}\n<\/code><\/pre>\n<p>That&#8217;s not the cause of your problem, however.<\/p>\n<p>Is there are good reason for you unarchiving your view controller yourself? If you&#8217;re not doing anything special, you can rely on the existing mechanisms to do it. The default implementation of init for a UIViewController looks for a nib with the same name as your view controller, and if it exists, it loads the nib (via initWithNibName).<\/p>\n<p>If there is data which you need to archive in and out, it may be that it shouldn&#8217;t be actually part of the UIViewController. Factor it out elsewhere perhaps?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Don&#8217;t forget to put the nil check in your init methods. E.g. the method you posted would be more correct if you wrote it as: &#8211; (id)initWithCoder:(NSCoder *)coder { if (self = [super initWithCoder:coder]) { [[self mapView] addAnnotations:[[coder decodeObjectForKey:@&#8221;Annotations&#8221;] retain]]; } return self; } That&#8217;s not the cause of your problem, however. Is there are [&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-5258","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5258","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=5258"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5258\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5258"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5258"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5258"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}