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

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.

1      

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.

1      

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.

1      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

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.