Swift Embedded print and Array subscripts

Hey!
I recently took a spin on swift embedded and checked out the Raspberry pi pico examples.
However, I hit a few issues while playing with the code.
The first issue is that printing to the debug console (e.g. when running on wokwi) prints only the last character of the string I’d like to print. However, for the simple example I played around with (the pico blink sdk sample code) printing works correctly when I put the code in the while loop, which I do not really understand.
Second issue I hit is that when declaring a simple array of e.g. integers, subscripts often just return the first item in the collection even though it should return a completley different element.
I am honestly not sure why that is happening and if the issue is on my side or if thats just bugs in the compiler.

So the issues looks like this:

let digitPins = [1, 2, 3, 4, 5]

func digit(digit: Int) -> Int {
    digitPins[digit]
}

@main
struct Main {
  static func main() {
    stdio_init_all()
    print("This just prints the last character of this string")
    while true {
      print("This prints the full string")
      print(digit(digit: Int.random(in: 0...3))) // this prints completely random integers, like 196608, which is clearly not in the array
    }
  }
}


Can someone tell me what I might do wrong here?
Thanks in advance!

Best,
Basti