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_gophpโ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.
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 โฆ
- open Xcode via clicking its macOS icon
- click โCreate a new Xcode projectโ button
- choose Application -> โCommand Line Toolโ then click โNextโ button
- Project Name: โSwift Command Lineโ
- Language: โSwiftโ then click โNextโ button
- in Project Navigator menu click โmainโ to see the default Swift code
- 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 - 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
- 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
- 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 ...
- open Terminal via clicking its macOS icon
- 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 ... - 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 ... - 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.