Xcode Command Line Project Executable Tutorial
โœ‚๐Ÿƒ๐Ÿพโ€โ™€๏ธ๐Ÿƒ๐Ÿผโ€โ™‚๏ธ
๐Ÿ“–

Xcode Command Line Project Executable Tutorial

Xcode Command Line Project Executable Tutorial

Yesterdayโ€™s Xcode Swift Command Line Project Primer Tutorial combines with our recent macOS find related work, so that, today, weโ€™ve written a small PHP โ€œhelperโ€ web application, which โ€œfishes outโ€ that Xcode macOS executable, and executes it for you, that we want you to download to (the Document Root of) a macOS MAMP local Apache/PHP/MySql web server environment, โ€œIntranet styleโ€, as has also been a theme of our work recently.

What are the modes of use of this PHP โ€œhelperโ€ web application? Well, any of โ€ฆ

  • surfing the web โ€ฆ via web browser URL like โ€ฆ
    HTTP://localhost:8888/find_executable_and_go.php?inproject=Swift%20Command%20Line&argvs=one+two+three
    โ€ฆ or fill out a form at find_executable_and_goโšซphpโ€˜s liveโœ‚run link
  • curl โ€ฆ via macOS command like โ€ฆ
    curl "HTTP://localhost:8888/find_executable_and_go.php?inproject=Swift%20Command%20Line&argvs=one+two+three"
  • PHP on command line โ€ฆ via macOS command like โ€ฆ


    php find_executable_and_go.php one two three


    โ€ฆ and fill out the Xcode project name

โ€ฆ or, after your downloading to macOS (where youโ€™ve installed, and are using, Xcode), the ideas below could work โ€ฆ



Previous relevant Xcode Swift Command Line Project Primer Tutorial is shown below.

Xcode Swift Command Line Project Primer Tutorial

Xcode Swift Command Line Project Primer Tutorial

The macOS Xcode IDE (Integrated Development Language) is a great place to create many and various types of executable software. The language Swift is Appleโ€™s language of choice, within Xcode, for โ€ฆ

  • iOS mobile apps โ€ฆ and today we build a simple โ€ฆ
  • macOS command line app

โ€ฆ which we allow to process your command line arguments. Then โ€œwe fish outโ€ where Xcode has stored the resultant Swift command line executable, and execute that โ€œbinaryโ€.

All told, we โ€ฆ

  1. open Xcode via clicking its macOS icon
  2. click โ€œCreate a new Xcode projectโ€ button
  3. choose Application -> โ€œCommand Line Toolโ€ then click โ€œNextโ€ button
  4. Project Name: โ€œSwift Command Lineโ€
  5. Language: โ€œSwiftโ€ then click โ€œNextโ€ button
  6. in Project Navigator menu click โ€œmainโ€ to see the default Swift code
  7. we end up making our code be like mainโšซswift โ€ฆ


    //

    // main.swift

    // Swift Command Line

    //

    // Created by User on 10/4/22.

    //



    import Foundation



    var msg = ""

    var i = 2



    if CommandLine.arguments.count <= 1
    {
    print("Hello, World!")
    }
    else
    {
    msg = CommandLine.arguments[1]
    while i < CommandLine.arguments.count
    {
    msg += " " + CommandLine.arguments[i]
    i += 1
    }
    print(msg)
    }

    ... via good help from this link, thanks
  8. to execute in Xcode's Console we choose the menu option Product -> "Run" and see the results down the bottom to left in Xcode's Console with "Hello, World!" output because there are no command line arguments as the default condition
  9. to execute within Xcode with command line arguments ...
    • we choose the menu option Swift Command Line -> "Edit Schema..."
    • we choose the menu option Info -> Build Configuration -> "Release"
    • we click "Arguments" tab
    • we click "Arguments Passed on Launch" tab's "+" button ... and ...
    • type in "one two three four five" as our user specific command line arguments
    • click "Close" button
  10. we choose the menu option Product -> "Run" and see the results down the bottom to right in Xcode's Console with "one two three four five"

... and then (with thanks to advice of this link) we ...

  1. open Terminal via clicking its macOS icon
  2. type in the command (where, for us, /Users/user can equate to $HOME if you'd prefer) ...


    find /Users/user/Library/ -name "Swift Command Line" -exec file {} \; 2> /dev/null


    ... leading us to conclude that ...
  3. typing in ...


    "/Users/user/Library//Developer/Xcode/DerivedData/Swift_Command_Line-ayzqxnplmfgugrclirdeaxwmiryj/Build/Products/Release/Swift Command Line"


    ... would result in the output "Hello, World!" (as it did) ... and ...
  4. typing in ...


    "/Users/user/Library//Developer/Xcode/DerivedData/Swift_Command_Line-ayzqxnplmfgugrclirdeaxwmiryj/Build/Products/Release/Swift Command Line" one three five


    ... would result in the output "one three five" (as it did)

We hope this is of interest to beginners in Swift and Xcode IDE software development in macOS operating system.

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

This entry was posted in eLearning, Operating System, Tutorials and tagged , , , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *