|
I have a json string and need to decode it to populate a List. So far, so good, but I am facing a problem with the Initialization of my view: Cannot convert value of type 'ChannelsData.Type' to expected argument type 'ChannelsData' the error happens at the line:
I just can't find a solution to this problem. I thank you folks for any help. At this time, the code I have is this:
The ChannelsData Struct is:
and the json (some of it) is:
|
|
Your
In the preview you are passing the
You have two options to fix the error. The first option is to comment out the preview struct. That will remove the build error, but you will not be able to preview in Xcode. The second option is to provide an instance of
By adding the parentheses, you are creating an instance of You may have to supply some arguments in the call to |
|
The error you're encountering arises because you're trying to pass the type ChannelsData instead of an instance of it. Instead of UserAuthResult(channels: ChannelsData), you need to initialize UserAuthResult with an instance of ChannelsData. Assuming channelsList is your JSON string, you should decode it first and then pass the decoded data to UserAuthResult. For instance: let decodedChannelsData = try JSONDecoder().decode(ChannelsData.self, from: jsonData) UserAuthResult(channels: decodedChannelsData) |
|
Thanks for your answer. I changed the code from:
to:
This removed the error in the code but, when canvas try to preview the view it crashes with an error:
|
|
Ok, changed the code to have as much parameters as needed. First it didn't work saying that some parameter was stil missing, but after I restarted xcode, it worked fine Thanks to all for the help. The actual init code is:
|
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.