GO FURTHER, FASTER: Try the Swift Career Accelerator today! >>

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 RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's all new Paywall Editor allow you to remotely configure your paywall view without any code changes or app updates.

Click to save your free spot now

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.