{"id":182,"date":"2008-12-12T22:48:27","date_gmt":"2008-12-13T03:48:27","guid":{"rendered":"http:\/\/vgable.com\/blog\/2008\/12\/12\/catching-nil-member-variables\/"},"modified":"2008-12-12T22:52:17","modified_gmt":"2008-12-13T03:52:17","slug":"catching-nil-member-variables","status":"publish","type":"post","link":"https:\/\/vgable.com\/blog\/2008\/12\/12\/catching-nil-member-variables\/","title":{"rendered":"Catching nil Member Variables"},"content":{"rendered":"<p>When I wrote this method it seemed like it would be helpful,<\/p>\n<p><code>\/\/log a warning for any member variable that nil<br \/>\n- (void) warnOfNilIVars;<br \/>\n{<br \/>\n&nbsp;&nbsp;unsigned int ivarCount = 0;<br \/>\n&nbsp;&nbsp;Ivar * ivarList = class_copyIvarList([self class], &ivarCount);<br \/>\n&nbsp;&nbsp;if(ivarList) {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;for(int i = 0; i < ivarCount; i++){<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;const char *typeString = ivar_getTypeEncoding(ivarList[i]);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(typeString && typeString[0] == '@')<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!object_getIvar(self, ivarList[i]))<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NSLog(@\"***WARNING: ivar %s of %@ is nil\", ivar_getName(ivarList[i]), [self className]);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;free(ivarList);<br \/>\n&nbsp;&nbsp;}<br \/>\n}<br \/><\/code><\/p>\n<p>But in practice I haven&#8217;t really used it (and when I have there were quite a few false-positives).  Still, I think it&#8217;s pretty neat that you can do something like this in Objective-C.<\/p>\n<p>If you find a use for it, please let me know!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When I wrote this method it seemed like it would be helpful, \/\/log a warning for any member variable that nil &#8211; (void) warnOfNilIVars; { &nbsp;&nbsp;unsigned int ivarCount = 0; &nbsp;&nbsp;Ivar * ivarList = class_copyIvarList([self class], &#038;ivarCount); &nbsp;&nbsp;if(ivarList) { &nbsp;&nbsp;&nbsp;&nbsp;for(int i = 0; i < ivarCount; i++){ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;const char *typeString = ivar_getTypeEncoding(ivarList[i]); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(typeString &#038;&#038; typeString[0] [&hellip;]\n<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,5,13],"tags":[77,106,169,254],"class_list":["post-182","post","type-post","status-publish","format-standard","hentry","category-macosx","category-objective-c","category-sample-code","tag-debugging","tag-nil","tag-software-development","tag-unit-testing"],"_links":{"self":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts\/182","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/comments?post=182"}],"version-history":[{"count":0,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts\/182\/revisions"}],"wp:attachment":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/media?parent=182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/categories?post=182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/tags?post=182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}