Working With Files
Lesson 1 of 48 in Coddy's Swift for GDScript Developers course.
This course translates GDScript reasoning into Swift console programs. GDScript examples run as complete Godot SceneTree scripts, while Swift compiles sibling source files into one module. Do not import sibling Swift filenames. Foundation imports apply in each file that needs those APIs. Only main.swift contains top-level statements; helper functions and named types live in separate files. Compare Variant bindings and reference containers with Swift static types and value semantics as the course progresses.
The first task is complete. Run it to observe the input/output contract, then inspect Functions.swift. Later tasks ask for public APIs and returned output text from solve, while the locked driver prints and independently checks required behavior. These are standard console exercises, without SwiftUI or external packages. The GDScript comparisons deliberately separate RefCounted objects from Nodes and explicitly quit their script runner.
Challenge
EasyRun the supplied program. Input is one ASCII name of 1 to 20 letters. welcome(_:) returns Hello, followed by that name. The driver prints it. All Swift files compile together; top-level statements belong only in main.swift. In this multi-file Swift executable, main.swift is the entry file; GDScript instead runs through a Godot script entry and does not require that Swift filename. Free functions live in Functions.swift; later named types each have their own file.
Implement the required APIs and solve(_ input: String) -> String. Return output text without a final newline; do not print in editable code. The locked driver independently checks the APIs on additional valid inputs, then prints the returned text with exactly one newline. All numeric operations stay within Int bounds.
Your code goes in Functions.swift. main.swift holds the supplied input/output code and cannot be edited.
Try it yourself
import Foundation
func apiChecks(_ input: String) -> Bool {
return welcome("Ada") == "Hello, Ada"
}
let input = String(data: FileHandle.standardInput.readDataToEndOfFile(), encoding: .utf8)!
// BEGIN PUBLIC API PROBES
let apiOK = apiChecks(input)
// END PUBLIC API PROBES
if apiOK { print(solve(input)) } else { print("API mismatch") }
All lessons in Swift for GDScript Developers
1Starting Swift
Working With FilesBindings and MutationNumbers and ConversionBoolean ConditionsRecap: Fare Quote4Functions and Arrays
Functions and LabelsInout and Exclusive AccessTuples and Multiple ResultsArrays Have Value SemanticsRecap: Rising Steps2Text and Decisions
Strings and InterpolationOptionals and BindingGuard and Early ExitIf and Branch ValuesRecap: Entry RulesPractice on your own: Swift playground