It's helpful to experiment with language syntax in a REPL tool before pasting code into your editor.
REPL is an acryonym for Read, Evaluate, Print, Loop. REPL tools are simple interactive programming environments primarily used to validate syntax and algorithms.
The main Swift REPL tool is the Playground feature included with the Xcode IDE, accessible from the File/New menu. For iOS, macOS development, this is probably the only tool you'll ever need.
Apple has also published an iPad app that provides the same functionality on that device.
For those not using Xcode, there are some web based implementations, such as:
The Kotlin team provides a first-party REPL, also called Playground.
JSFiddle - for testing web development ideas