Another consolidation day done – I’m liking these. While I’m missing writing code and learning new concepts, I’m sure that I’ll be back into that quite soon. For now, it’s just nice to have some cementing of knowledge happening.
Something that I previously found a bit confusing but makes sense now – and that (instructor) Paul refers to as being very Swifty is the use of internal and external parameters in functions. So, moving from this:
func countLettersInString(myString: String) {
print("The string \(myString) has \(myString.count) letters.")
}
countLettersInString(myString: "Hello")
To one of these approaches which read much closer to English:
func countLetters(in str: String) {
print("The string \(str) has \(str) letters.")
}
func countTheLetters(_ str: String) {
print("The string \(str) has \(str) letters.")
}
countLetters(in: "Hello")
countTheLetters("Hello")