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

Day9 - access control - test

Forums > 100 Days of Swift

Can someone clarify this to me please ?

Q4: - I chose false, because there is a private property and no custom init - and the answer was wrong struct Contributor { private var name = "Anonymous" } let paul = Contributor()

Q6: - I chose false, on the same idea as above - and the answer is right struct Doctor { var name: String var location: String private var currentPatient = "No one" } let drJones = Doctor(name: "Esther Jones", location: "Bristol")

What is the difference between these 2?

Also I tried these 2 scenarios in playground and they are both false.

3      

What are the questions? Sorry, it's been a while since I went through this.

At any rate, the difference between these two structs:

The second struct has non-private properties that do not have a default value, so they have to be initialized when the struct is created. The compiler will automatically generate a memberwise initializer for those properties.

The first struct has just one property and it has a default value, so the compiler will not generate a memberwise initializer for it. It's also private, so there wouldn't be a generated init anyway, even if there was no default value. You would get a compile error because there would be no way to initialize the struct.

3      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

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.