UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Day six, loops

Forums > 100 Days of SwiftUI


let platforms = ["iOS", "macOS", "tvOS", "watchOS"]

for os in platforms {
    print("Swift works great on \(os).")
}

When I run the code above in playground, it prints the final element of the array only. When run my output is:

Array of 4 String elements
[several blank lines]
 "Swift works great on watchOS.\n"

Expected behavior?

Sonoma 14.2, Xcode 15.0.1

edit: running the swift code from the command-line displays each element.

2      

When I run in playground, get this

Swift works great on iOS.
Swift works great on macOS.
Swift works great on tvOS.
Swift works great on watchOS.

2      

Thanks for the reply,

I'm not allowed to insert an image or to link to an image, unfortunately. I wanted to show exactly what I was seeing

I have two panels:

The left-hand panel, where I'm entering code, has line-numbers. The right-hand panel shows only partial output.

the screencap can be seen at http // jocala dot com / play.png

2      

You need to show the debug area. You can do this under the View menu, or using ⇧⌘Y

2      

See this

Playgroung

PS to insert image I use Dropbox (allowed link) and then change the last bit of url (dl=0) to raw=1 then it should work

3      

Thanks! I'm all sorted out and proceeding onward. Day seven!

2      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.