|
Hi I am new to Swift and have decided to try to learn it. I have been following along with the course and I have been typing in the code as it is presented but I get an error with the let menu = Bundle....yada yada. I get three errors when compiling. I have physically typed it and I have cut and pasted it and get the same results with each method. Any help? Screen Shot https://imgur.com/a/Ce871Jw |
|
|
|
@roonToon has some issues with the
Couple of things. First, welcome to HackingWithSwift and this wonderful course. Second, please ask questions. There are many here willing to help. Next, helpers often try to run your code to find the error. So I offer this critique. I do not want to re-type your code. I prefer to copy/paste your code from this forum into a test application, or a Please add loads of comments to your code. What do you understand? What do you think the code should do? This helps us point you in the right direction, or perhaps, uncover the root cause of your understanding. Yada, yada. Also, your error code is pretty clear. It seems you are trying to decode some JSON that should resolve into an array of Yikes! How is Swift supposed to decode JSON into chunks of MenuSections if you're not including What day are you on with your 100 Days of SwiftUI journey? Please tell us what day you are on, so we can point you to the lesson that you need to revisit and study! Good luck Keep Coding! |
|
From this tutorial. Building a menu using List This is the line I am getting the errors on. let menu = Bundle.main.decode([MenuSection].self, from: "menu.json") The errors are. Cannot convert value of type '[Any]' to expected argument type 'T.Type' Cannot find 'MenuSection' in scope Generic parameter 'T' could not be inferred
|
|
Now we're getting somewhere! This line says "I have a file of JSON and I want to turn it into an array of MenuSection objects.
Also, you noted the lesson: Building a menu using List Here's an important line from that lesson.
I don't think you have Menu.swift in your solution. You are missing these key structures. Where is your definition of |
|
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 more!
Sponsor Hacking with Swift and reach the world's largest Swift community!
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.
Link copied to your pasteboard.