{"id":226249,"date":"2019-01-08T15:26:39","date_gmt":"2019-01-08T07:26:39","guid":{"rendered":"http:\/\/magicalbits.net\/?p=226249"},"modified":"2019-01-08T15:26:39","modified_gmt":"2019-01-08T07:26:39","slug":"dynamiccallable-unix-tools-as-swift-functions-the-always-right-institute-almost-always-sometimes-definitely-right","status":"publish","type":"post","link":"https:\/\/magicalbits.net\/?p=226249","title":{"rendered":"@dynamicCallable: Unix Tools as Swift Functions \u2013 The Always Right Institute \u2013 Almost always sometimes definitely right."},"content":{"rendered":"<blockquote><p>Wait what?! We want to call arbitrary commandline tools from within Swift, like so:<\/p>\n<pre class=\"highlight\"><code><span class=\"k\">for<\/span> <span class=\"n\">file<\/span> <span class=\"k\">in<\/span> <span class=\"n\">shell<\/span><span class=\"o\">.<\/span><span class=\"nf\">ls<\/span><span class=\"p\">(<\/span><span class=\"s\">\"\/Users\/\"<\/span><span class=\"p\">)<\/span><span class=\"o\">.<\/span><span class=\"nf\">split<\/span><span class=\"p\">(<\/span><span class=\"nv\">separator<\/span><span class=\"p\">:<\/span> <span class=\"s\">\"<\/span><span class=\"se\">\\n<\/span><span class=\"s\">\"<\/span><span class=\"p\">)<\/span> <span class=\"p\">{<\/span>\n    <span class=\"nf\">print<\/span><span class=\"p\">(<\/span><span class=\"s\">\"dir:\"<\/span><span class=\"p\">,<\/span> <span class=\"n\">file<\/span><span class=\"p\">)<\/span>\n<span class=\"p\">}<\/span><\/code><\/pre>\n<\/blockquote>\n<p>Source: <em><a href=\"http:\/\/www.alwaysrightinstitute.com\/swift-dynamic-callable\/\">@dynamicCallable: Unix Tools as Swift Functions \u2013 The Always Right Institute \u2013 Almost always sometimes definitely right.<\/a><\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Wait what?! We want to call arbitrary commandline tools from within Swift, like so: for file in shell.ls(&#8220;\/Users\/&#8221;).split(separator: &#8220;\\n&#8221;) { print(&#8220;dir:&#8221;, file) } Source: @dynamicCallable: Unix Tools as Swift Functions \u2013 The Always Right Institute \u2013 Almost always sometimes definitely right.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ep_exclude_from_search":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-226249","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/magicalbits.net\/index.php?rest_route=\/wp\/v2\/posts\/226249","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/magicalbits.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/magicalbits.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/magicalbits.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/magicalbits.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=226249"}],"version-history":[{"count":1,"href":"https:\/\/magicalbits.net\/index.php?rest_route=\/wp\/v2\/posts\/226249\/revisions"}],"predecessor-version":[{"id":226250,"href":"https:\/\/magicalbits.net\/index.php?rest_route=\/wp\/v2\/posts\/226249\/revisions\/226250"}],"wp:attachment":[{"href":"https:\/\/magicalbits.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=226249"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/magicalbits.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=226249"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/magicalbits.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=226249"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}