Hi, I'am learning how to compue property values dynamically on Day 10 's Struct -themed tutorials.
"https://www.hackingwithswift.com/quick-start/beginners/how-to-compute-property-values-dynamically"
I found it was confusing to decide when to use () and when to use "." , if I want to pass in a value to an instance or to a method.
Here is what Paul wrote :
struct Employee {
let name: String
var vacationAllocated = 14
var vacationTaken = 0
var vacationRemaining: Int {
vacationAllocated - vacationTaken
}
}
var archer = Employee(name: "Sterling Archer", vacationAllocated: 14)
archer.vacationTaken += 4
print(archer.vacationRemaining)
archer.vacationTaken += 4
print(archer.vacationRemaining)
when I tried to write it in my Playground, I mistakenly wrote
var archer = Employee(name: "Sterling Archer", vacationAllocated: 14)
archer (vacationTaken: 4)
print(archer.vacationRemaining)
Then I reliazed Paul used "." when calling out archer's vacationTaken property.
My question is: Is there a general rule about "When to use . and when to use ()" ?
Or we just need to remember where to use what ?
Thank you in advance
Boat