Does VStack/ScrollView combination not work any more in iOS Swift Playgrounds for iPad (ver 3.4) ?

This code runs fine on MBP in Xcode. But in iOS Swift Playgrounds it fails on line 9 with:

There was a problem encountered while running this playground. Check your code for mistakes

on iPad from a start up Blank 5.3 playground.

Code Block swift
import PlaygroundSupport
import SwiftUI
struct ContentView: View {
    var emojis = "🐿 🐝🦋🐌🐞🐜🐛🦒🐘🦛🦓🦏🐪"
    var body: some View {
        VStack {
            ScrollView(.horizontal) {
                HStack {
                    ForEach( emojis.map { String($0) }, id: \.self ) { emoji in
                        Text(emoji).font(Font.system(size: 45))
                    }
                }
                .padding(.horizontal)
            }
            Color.yellow
            .edgesIgnoringSafeArea([.horizontal, .bottom])
        }
        .background(Color.white)
    }
}
PlaygroundPage.current.setLiveView( ContentView() )


I have whittled this code down a lot from the Stanford SwiftUI 2020 course posted on YouTube. The whole EmojiArt app worked flawlessly as of lecture 7 in iOS Swift Playgrounds for iPad in version 3.2 a few days ago before the upgrade to version 3.4.

Now, this, as well as many other apps have all broken after the iOS Swift Playgrounds app updated to version 3.4.

Replies

I copied your code it and confirmed that it didn't run in Playgrounds 3.4. If you take out

Code Block language
Color.yellow.edgesIgnoringSafeArea([.horizontal, .bottom])

your code runs as expected. What are you trying to make yellow?
@Tylor,

The yellow is the "canvas" where images would be dragged from a side-by-side safari app. Again, this is an extremely cut down fraction of the app that ran fine in version 3.2 for Stanford's 2020 SwiftUI course: Posted on You tube lecture 6, 7, and 8. If you go to you tube (link is restricted from posting here) and search for Stanford 2020 SwiftUI lecture 6, and got to time stamp 00:37:20, you'll see what this should look like when running.

I was starting lecture 8 and all was working fine on iPad .. then the update hit, and all my apps in iOS Swift Playgrounds for iPad BROKE !

The whole "EmojiArt" app is teaching dragging and objects (such as the emojis from the pallet at the top, and images for the background from Safari in a side-by-side), also teaching persistence with UserDefaults, and adding more experience with programming in SwiftUI.

@Tylor,

When I take out the .edgesIgnoringSafeArea[] line, the app starts, but the horizontal scroll view at the top fails to scroll ... and if you try the app crashes. (Actually, after the view comes up, the app will crash within 5 seconds without the user trying to interact at all.)

@richiwalt,

I answered a different question on the forms and I think the issue is the same. After the update to 3.4, I don't think the screen size of the live view is being registered currently inside the ContentView (or any view) which is leading to unexpected behavior for views that need that information.

Code Block Swift
struct ContentView: View {
    var emojis = "🐿 🐝🦋🐌🐞🐜🐛🦒🐘🦛🦓🦏🐪"
    var body: some View {
        VStack {
            ScrollView(.horizontal) {
                HStack {
                    ForEach( emojis.map { String($0) }, id: \.self ) { emoji in
                        Text(emoji).font(Font.system(size: 45))
                    }
                }
                .padding(.horizontal)
            }
            Color.yellow.edgesIgnoringSafeArea([.horizontal, .bottom])
        }
        .frame(width: 500, height: 500)
        .background(Color.white)
    }
}

If you add the frame modifier it seems to make it work in the meantime. It scrolls left and right without crashing.
Taylor wrote:

@richiwalt,

I answered a different question on the forms and I think the issue is the same. After the update to 3.4, I don't think the screen size of the live view is being registered currently inside the ContentView (or any view) which is leading to unexpected behavior for views that need that information.

Thanks, that probably explains many of my apps that are now failing ... but I don't think it covers all of them that fail. This update looks promising with a console we now have for print() statements ... but it seems there is a ways to go to get it back on par of reliably of the previous version. I wonder if this is part of what may eventually become Xcode on iPad ?