{"id":9211,"date":"2022-03-16T20:55:19","date_gmt":"2022-03-16T20:55:19","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=9211"},"modified":"2022-03-16T20:55:19","modified_gmt":"2022-03-16T20:55:19","slug":"creating-a-console-app-in-swift-on-linuxpart-2","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/creating-a-console-app-in-swift-on-linuxpart-2\/","title":{"rendered":"Creating a console app. in Swift (on Linux)(part 2)"},"content":{"rendered":"<p>In my post <a href=\"http:\/\/putridparrot.com\/blog\/creating-a-console-app-in-swift-on-linux\/\" rel=\"noopener\" target=\"_blank\">Creating a console app. in Swift (on Linux)<\/a> I demonstrated creating a console app. using Swift. I used top level statement to create the application, but there&#8217;s another way.<\/p>\n<p><em>Note: Those familiar with C# will see how C# now offers both the traditional class based Program as well as top level statement style, well Swift offers similar.<\/em><\/p>\n<p>After creating your application using<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nswift package init --type executable\r\n<\/pre>\n<p>Create a file in the Sources folder named <em>App.swift<\/em> or whatever you like except I found that <em>main.swift<\/em> didn&#8217;t seem to work and caused errors such as <em>error: &#8216;main&#8217; attribute cannot be used in a module that contains top-level code<\/em>.<\/p>\n<p>Now in your App.swift paste the following<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n@main\r\nstruct App {\r\n    static func main() {\r\n        print(&quot;Hello World&quot;)\r\n    }\r\n}\r\n<\/pre>\n<p><em>Note: The @main attribute is important to mark the type as the main application code.<\/em><\/p>\n<p>If you now use the following from the command line, you should see <em>Hello World<\/em> output.<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nswift run\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In my post Creating a console app. in Swift (on Linux) I demonstrated creating a console app. using Swift. I used top level statement to create the application, but there&#8217;s another way. Note: Those familiar with C# will see how C# now offers both the traditional class based Program as well as top level statement [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[286],"tags":[],"class_list":["post-9211","post","type-post","status-publish","format-standard","hentry","category-swift"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/9211","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=9211"}],"version-history":[{"count":2,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/9211\/revisions"}],"predecessor-version":[{"id":9286,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/9211\/revisions\/9286"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=9211"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=9211"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=9211"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}