WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

SOLVED: Creating Views in a Loop: Build Failure

Forums > 100 Days of SwiftUI

I am going through Day 16: Creating Vews in a Loop and have copied the below code from the lesson into my playground and get 3 compiler issues and the build fails.

struct ContentView: View {
    let students = ["Harry", "Hermione", "Ron"]
    @State private var selectedStudent = "Harry"

    var body: some View {
        NavigationView {
            Form {
                Picker("Select your student", selection: $selectedStudent) {
                    ForEach(students, id: \.self) {
                        Text($0)
                    }
                }
            }
        }
    }
}

Here are the build issues

1) Command EmitSwiftModule failed with a nonzero exit code 2) No such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.2.sdk' 3) Unable to load standard library for target 'x86_64-apple-ios15.0-simulator'

Any help to resolve the issues would be much appreciated. Up to this point all the code I have copied from the lessons has run fine.

   

I am not sure you have ALL the code you need to run this in a playground.

Please add these two lines before your ContentView:

import PlaygroundSupport
import SwiftUI

Please add this line after your ContentView:

PlaygroundPage.current.setLiveView( ContentView().frame(width: 400, height: 300, alignment: .center) )

I copy / pasted your code into Playgrounds, added these lines, and I assure you, they work as expected.

Let's Play a Game

Unfortunately, this is a terrible game new XCode programmers have to play sometimes. It's called "What did I do wrong?"

The twist to this game is that sometimes, it's not you!

Many of us do not have the patience to figure out what's really going on in these cases. However, I see the following two clues in your error messages...

apple-ios15.0-simulator
iPhoneSimulator15.2.sdk

Now, I do not know for sure that this is the root of your issue. However, @twostraws spent considerable effort and time last November to update all his tutorials to support the latest versions of XCode and iOS operating systems.

WIthout too much information, it seems you may be trying to run your code using iOS 15.2, and an older simulator. I DO NOT KNOW. These may be generic names for internal software bits.

Do you see my point?

I am running the latest XCode, with the latest iOS simulators. Your code works fine.

This code doesn't work for you. Some clues indicate you may not be running the latest versions of XCode or iOS simulators.

   

Thanks for your help, @Obelix.

As the saying goes, if all else fails restart (or something like that ;-)).

So I quit Xcode and restarted.

Got a message that some resources need to be installed. Once installed, like magic, the code ran.

Who knows but at least problem solved.

Thanks again for your help.

   

Hacking with Swift is sponsored by Fernando Olivares

SPONSORED Fernando's book will guide you in fixing bugs in three real, open-source, downloadable apps from the App Store. Learn applied programming fundamentals by refactoring real code from published apps. Hacking with Swift readers get a $10 discount!

Read the book

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.