{"id":19404,"date":"2017-10-31T14:52:01","date_gmt":"2017-10-31T18:52:01","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=19404"},"modified":"2017-10-31T14:53:21","modified_gmt":"2017-10-31T18:53:21","slug":"selective-selector-mapping","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2017\/10\/31\/selective-selector-mapping\/","title":{"rendered":"Selective Selector Mapping"},"content":{"rendered":"<p><a href=\"http:\/\/indiestack.com\/2017\/10\/selective-selector-mapping\/\">Daniel Jalkut<\/a>:<\/p>\n<blockquote cite=\"http:\/\/indiestack.com\/2017\/10\/selective-selector-mapping\/\">\n<p>It turns that adding that protocol conformance onto my class declaration not only gains me Swift&rsquo;s protocol type checking, but <em>changes<\/em> the way key functions are mapped from Swift to Objective-C:<\/p>\n<pre>class MyDataSource: NSObject, NSTableViewDataSource {\n    func numberOfRows(in tableView: NSTableView) -&gt; Int {\n        return 0\n    }\n}\n\nlet thisSource = MyDataSource()\nthisSource.responds(to: Selector(\"numberOfRowsInTableView:\")) \/\/ true\n<\/pre>\n<p>Armed with the knowledge that my class <em>intends to comply<\/em> with <code>NSTableViewDataSource<\/code>, Swift generates the expected mapping to Objective-C.<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Daniel Jalkut: It turns that adding that protocol conformance onto my class declaration not only gains me Swift&rsquo;s protocol type checking, but changes the way key functions are mapped from Swift to Objective-C: class MyDataSource: NSObject, NSTableViewDataSource { func numberOfRows(in tableView: NSTableView) -&gt; Int { return 0 } } let thisSource = MyDataSource() thisSource.responds(to: Selector(\"numberOfRowsInTableView:\")) [&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,30,1529,54,71,901],"class_list":["post-19404","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-cocoa","tag-mac","tag-macos-10-13","tag-objective-c","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/19404","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=19404"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/19404\/revisions"}],"predecessor-version":[{"id":19408,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/19404\/revisions\/19408"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=19404"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=19404"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=19404"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}