{"id":3878,"date":"2014-03-30T06:10:29","date_gmt":"2014-03-30T06:10:29","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-give-an-external-property-to-uibutton-collection-of-common-programming-errors\/"},"modified":"2014-03-30T06:10:29","modified_gmt":"2014-03-30T06:10:29","slug":"how-to-give-an-external-property-to-uibutton-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-give-an-external-property-to-uibutton-collection-of-common-programming-errors\/","title":{"rendered":"How to give an external property to UIButton-Collection of common programming errors"},"content":{"rendered":"<p>You can either create a <code>UIButton<\/code> subclass, or use Obj-C runtime associations like this<\/p>\n<pre><code>#import \n\nstatic char kMyExtendedPropKey;\nobjc_setAssociatedObject(myButton,\n                         &amp;kMyExtendedPropKey,\n                         yourObjectToAssociate,\n                         OBJC_ASSOCIATION_RETAIN);\n<\/code><\/pre>\n<p>Note that associations can be used in conjunction with categories to add new properties to existing classes! But use with caution, <strong>subclassing is the preferred way<\/strong>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can either create a UIButton subclass, or use Obj-C runtime associations like this #import static char kMyExtendedPropKey; objc_setAssociatedObject(myButton, &amp;kMyExtendedPropKey, yourObjectToAssociate, OBJC_ASSOCIATION_RETAIN); Note that associations can be used in conjunction with categories to add new properties to existing classes! But use with caution, subclassing is the preferred way.<\/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-3878","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3878","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=3878"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3878\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3878"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3878"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3878"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}