{"id":24135,"date":"2019-01-31T16:30:50","date_gmt":"2019-01-31T21:30:50","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=24135"},"modified":"2019-02-01T08:15:10","modified_gmt":"2019-02-01T13:15:10","slug":"swift-objc-bridge-using-dynamiccallable","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2019\/01\/31\/swift-objc-bridge-using-dynamiccallable\/","title":{"rendered":"Swift-ObjC Bridge Using @dynamicCallable"},"content":{"rendered":"<p><a href=\"http:\/\/www.alwaysrightinstitute.com\/swift-objc-bridge\/\">Helge He&szlig;<\/a>:<\/p>\n<blockquote cite=\"http:\/\/www.alwaysrightinstitute.com\/swift-objc-bridge\/\">\n<p>Of course Swift already has Objective-C integrated on the Apple platforms,\ndirectly supported by the compiler, as well as the associated\nbridging runtime. Yet using \n<a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/master\/proposals\/0216-dynamic-callable.md\">Dynamic Callable<\/a>\nyou can actually build something similar at the library level,\nand we want to show you how that would look like.<\/p>\n<p>[&#8230;]<\/p>\n<p>You may have wondered that <code>arrayByAddingObject:<\/code> instead of <code>addObject:<\/code> \nwas used to demo the thing. That had a reason &#x1F61C;\nOur signatures deal with methods returning object values, but <code>addObject:<\/code>\nis a <code>Void<\/code> method. If we invoke it, we crash, because ARC will attempt to\nrelease the non-existing result.<\/p>\n<\/blockquote>\n<p>It&rsquo;s a fun demo, but real-world bridging is complicated by memory management, error parameters and exceptions, non-object types, etc.<\/p>\n\n<p>Previously: <a href=\"https:\/\/mjtsai.com\/blog\/2018\/12\/27\/dynamiccallable-unix-tools-as-swift-functions\/\">@dynamicCallable: Unix Tools as Swift Functions<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>Helge He&szlig;: Of course Swift already has Objective-C integrated on the Apple platforms, directly supported by the compiler, as well as the associated bridging runtime. Yet using Dynamic Callable you can actually build something similar at the library level, and we want to show you how that would look like. [&#8230;] You may have wondered [&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":"2019-01-31T21:30:51Z","apple_news_api_id":"f8a58453-854f-41ff-ab7c-9fd9f36a974b","apple_news_api_modified_at":"2019-02-01T13:15:14Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAA==","apple_news_api_share_url":"https:\/\/apple.news\/A-KWEU4VPQf-rfJ_Z82qXSw","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":[55,571,54,760,71,901],"class_list":["post-24135","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-arc","tag-memory-management","tag-objective-c","tag-objective-c-runtime","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/24135","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=24135"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/24135\/revisions"}],"predecessor-version":[{"id":24144,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/24135\/revisions\/24144"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=24135"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=24135"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=24135"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}