NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

SOLVED: Moonshot project - Error in Xcode

Forums > 100 Days of SwiftUI

Hello all, I am following the lesson of the day 40. And I have an Xcode error that won't let me compile the code. Compared to Paul's code, I don't see any difference. Has this happened to anyone else or do you know how to solve it? Thank you very much!!

struct Bundle {
    func decode(_ file: String) -> [String: Astronaut] {
        guard let url = self.url(forResource: file, withExtension: nil) else { //Error here: 'nil' requires a contextual type - and: Value of type 'Bundle' has no member 'url'
            fatalError("Failed to locate \(file) in bundle.") // Locate JSON

        guard let data = try? Data(contentsOf: url) else {
            fatalError("Failed to load \(file) from bundle.") // Load JSON

        let decoder = JSONDecoder()

        guard let loaded = try? decoder.decode([String: Astronaut].self, from: data) else {
            fatalError("Failed to decode \(file) from bundle.") // Decode JSON


What's the error?


I have pasted the code now because the image I had uploaded has not loaded. Thanks!



struct Bundle {


extension Bundle {

because you are extending the existing Bundle type, not declaring a new type called Bundle.


You're right!! I hadn't noticed, thank you very much!


Hacking with Swift is sponsored by MadMachine

SPONSORED Want to explore your Swift skill outside of the Apple world? Join the MadMachine community and start to program microcontrollers in Swift.

Get it 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.