{"id":10307,"date":"2014-12-13T16:14:22","date_gmt":"2014-12-13T21:14:22","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=10307"},"modified":"2014-12-13T19:41:51","modified_gmt":"2014-12-14T00:41:51","slug":"what-happened-to-nsmethodsignature","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2014\/12\/13\/what-happened-to-nsmethodsignature\/","title":{"rendered":"What Happened to NSMethodSignature?"},"content":{"rendered":"<p><a href=\"https:\/\/developer.apple.com\/swift\/blog\/?id=19\">Apple<\/a>:<\/p>\n<blockquote cite=\"https:\/\/developer.apple.com\/swift\/blog\/?id=19\">\n<p>Bringing the Cocoa frameworks to Swift gave us a unique opportunity to look at our APIs with a fresh perspective. We found classes that we didn&rsquo;t feel fit with the goals of Swift, most often due to the priority we give to safety. For instance, some classes related to dynamic method invocation are not exposed in Swift, namely <code>NSInvocation<\/code> and <code>NSMethodSignature<\/code>.<\/p>\n<p>We recently received a bug report from a developer who noticed this absence. This developer was using <code>NSMethodSignature<\/code> in Objective-C to introspect the types of method arguments, and in the process of migrating this code to Swift, noticed that <code>NSMethodSignature<\/code> is not available.<\/p>\n<p>[&#8230;]<\/p>\n<p>With a combination of protocols and generics, we have written Swift code to elegantly create and register HTTP handlers of varying types. This approach also lets the compiler guarantee type safety, while ensuring excellent runtime performance.<\/p>\n<\/blockquote>\n<p><a href=\"http:\/\/owensd.io\/2014\/12\/12\/same-old-arguments.html\">David Owens<\/a>:<\/p>\n<blockquote cite=\"http:\/\/owensd.io\/2014\/12\/12\/same-old-arguments.html\"><p>Seriously, someone asks for the functionality for dynamic dispatch and you say you can do the same thing with static code! No, you cannot. You can mimic the behavior.<\/p>\n<p>Instead, you showed someone how to build a static registration table. Then you make the statement that it&rsquo;s &ldquo;type-safe&rdquo; while using <code>Any<\/code> as the arguments to the public API for <code>dispatch<\/code> and using type coercion&#8230; that&rsquo;s not type-safety. And let&rsquo;s be honest, it&rsquo;s really not that different then the validation one does for dynamic dispatch either.<\/p>\n<p>[&#8230;]<\/p>\n<p>You see, and this is the trade-off that you <em>never<\/em> mention. You paint an extremely biased position without covering the full gambit of what is really needed to build and maintain a system like you are proposing. The reality, it sucks. <\/p><\/blockquote>\n<p>Not to mention the <a href=\"https:\/\/twitter.com\/iljawascoding\/status\/543865022699814914\">other<\/a> things you can do with <code>NSInvocation<\/code> that can&rsquo;t be mimicked with static code.<\/p>\n<p>Update (2014-12-13): <a href=\"https:\/\/twitter.com\/mernen\/status\/543750973832060928\">Daniel Luz<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/mernen\/status\/543750973832060928\"><p>I can only infer the use case from what was presented, but it seems to me you solved the wrong problem here<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Apple: Bringing the Cocoa frameworks to Swift gave us a unique opportunity to look at our APIs with a fresh perspective. We found classes that we didn&rsquo;t feel fit with the goals of Swift, most often due to the priority we give to safety. For instance, some classes related to dynamic method invocation are not [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[69,71,901],"class_list":["post-10307","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-cocoa","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/10307","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=10307"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/10307\/revisions"}],"predecessor-version":[{"id":10315,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/10307\/revisions\/10315"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=10307"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=10307"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=10307"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}