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

SOLVED: Project 12: How to solve the challenges?

Forums > 100 Days of Swift

Hi!

I'm on day 49, project 12.

https://www.hackingwithswift.com/read/12/5/wrap-up

And i'm not able to make the challengues work. I used the codable way to save the data.

I cannot make the viewcontroller class part of codable protocol. Do i have to coform a separated struct or class for the data first?

Could anyone who solved this share the code of one of the challengues with me?

Thanks in advance!

3      

You wouldn't make the ViewController conform to Codable. Instead, you would make whatever object is providing the data for your ViewController be Codable so you could save it to UserDefaults.

So for Project 10, you would make the Person class conform to Codable and the save the people array, as shown here.

For Project 1, you would probably want to save a Dictionary consisting of image names and view counts.

For Project 2, you could get by with just saving the user's score as an Int.

Neither Dictionary* nor Int require any special work to conform to Codable; they just do so out of the box. It's only when you have custom types, like Person in Project 10, that you need to worry about doing it yourself.

* Well, it does as long as its key and value types themselves conform.

3      

Thank you roosterboy! You made it very clear for me.

I will do it in that way!

3      

Hey airbusdriverr,

Did you have much luck on Project 12? I've gotten a little stuck on the first challenge as well. Did you place the encode and the required init functions in the ViewController file or the DetailViewController? I assume the former. Any other tips would be great.

3      

Hey airbusdriverr,

Can you help with challenge 1? I do not know what to do. I was frozen.

3      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

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.