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

@day9. initializers**2

Forums > 100 Days of Swift

This is hard tobaco example in the test-cases

... but modified

struct Dict {
    var words = [String]()
    var wordz = Set<String>()
    var jesus  = String()
}
let dict = Dict()
print(dict.words.count)
print(dict.wordz.count)
print(dict.jesus)

... as an array or set could be understood as structs themselfs ... they have initializers themselfs? ... even a string itself has an initializer? ... so without an explicit initializer to Dict .... all the initializers of Array / Set / String is called when calling let dict = Dict() ?

Paul said one hour per day .... with examples like this ... digesting one test-case needs an hour (rofl)

3      

All types have an initializer, even if it's only a default one that the language provides automatically.

There are times you have to explicitly write an initializer, such as for a class that has no default values for its properties.

There are other times you do not have to write one because the compiler creates them for you, such as the memberwise initializer that all structs implicitly get.

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.