{"id":472,"date":"2010-12-03T09:45:54","date_gmt":"2010-12-03T14:45:54","guid":{"rendered":"http:\/\/www.jaimerios.com\/?p=472"},"modified":"2010-12-03T09:45:54","modified_gmt":"2010-12-03T14:45:54","slug":"how-do-i-know-if-a-method-is-available","status":"publish","type":"post","link":"https:\/\/jaimerios.com\/?p=472","title":{"rendered":"How do I know if a method is available?"},"content":{"rendered":"<p>This may seem like a silly post, but I have been talking to PC developers working on Mac OS code who are creating code like they are still working on the PC. So this is a note for them; things they should keep in the back of their mind when they are coding.<\/p>\n<p><strong>Mac OS SDKs<\/strong><br \/>\nWhen using different SDK&#8217;s in Mac OS Programming, there are ways for checking what SDK you have available. <\/p>\n<p>At build time, you can use the macros provided by Apple to check what&#8217;s available:<\/p>\n<pre LANG=\"C\">#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)\n#endif<\/pre>\n<p><strong>Checking for functionality<\/strong><br \/>\nAt runtime, if you are crossing library boundaries and calling a library that you didn&#8217;t build, you should check that the class you are sending a message to responds to that message by calling the respondsToSelector method. You can at that point decide what path to take, which is better then calling the method and proceeding with your code as if the previous call succeeded:<\/p>\n<pre LANG=\"OBJ-C\">- (void)hornMethod\n{\n    if ( [m_windClass respondsToSelector:@selector(blowThatHorn)] )\n    {\n        [m_windClass blowThatHorn];\n    }\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The Mac OS supports, and has for a long time now, methods for checking whether or not you have functionality available to you from the SDK or from a class that was built by another developer. This may be compared to COM, which is fair, but the implementation is much richer.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[105,113,180,288,506],"class_list":["post-472","post","type-post","status-publish","format-standard","hentry","category-coding","tag-calling-methods","tag-checking-for-methods","tag-dylib","tag-mac-os","tag-xcode"],"_links":{"self":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/posts\/472","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=472"}],"version-history":[{"count":0,"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/posts\/472\/revisions"}],"wp:attachment":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=472"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=472"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=472"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}