{"id":4609,"date":"2014-03-30T13:59:06","date_gmt":"2014-03-30T13:59:06","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/uiviewcategory-access-dealloc-or-do-something-on-uiview-dealloc-call-closed-collection-of-common-programming-errors\/"},"modified":"2014-03-30T13:59:06","modified_gmt":"2014-03-30T13:59:06","slug":"uiviewcategory-access-dealloc-or-do-something-on-uiview-dealloc-call-closed-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/uiviewcategory-access-dealloc-or-do-something-on-uiview-dealloc-call-closed-collection-of-common-programming-errors\/","title":{"rendered":"UIView+Category access dealloc or do something on UIView dealloc call [closed]-Collection of common programming errors"},"content":{"rendered":"<p>swizzle dealloc. it is evil but we do it too \ud83d\ude00<\/p>\n<p>in +load of your category swizzle dealloc and you&#8217;re in<\/p>\n<pre><code>#import \n#import \n\n@interface T : NSObject\n@end\n\n@interface T (myCat)\n@end\n\n@implementation T\n- (void)dealloc {\n    NSLog(@\"2\");\n}\n@end\n\n@implementation T (myCat)\n+ (void)load {\n    SEL originalSelector = @selector(NSSelectorFromString(dealloc));\n    SEL overrideSelector = @selector(xchg_dealloc);\n    Method originalMethod = class_getInstanceMethod(self, originalSelector);\n    Method overrideMethod = class_getInstanceMethod(self, overrideSelector);\n    if (class_addMethod(self, originalSelector, method_getImplementation(overrideMethod), method_getTypeEncoding(overrideMethod))) {\n        class_replaceMethod(self, overrideSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));\n    } else {\n        method_exchangeImplementations(originalMethod, overrideMethod);\n    }\n}\n- (void)xchg_dealloc {\n    NSLog(@\"1\");\n    [self xchg_dealloc]; \/\/calls original\n}\n@end\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>swizzle dealloc. it is evil but we do it too \ud83d\ude00 in +load of your category swizzle dealloc and you&#8217;re in #import #import @interface T : NSObject @end @interface T (myCat) @end @implementation T &#8211; (void)dealloc { NSLog(@&#8221;2&#8243;); } @end @implementation T (myCat) + (void)load { SEL originalSelector = @selector(NSSelectorFromString(dealloc)); SEL overrideSelector = @selector(xchg_dealloc); Method [&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-4609","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4609","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=4609"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4609\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4609"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4609"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4609"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}