Reputation: 71
What does it mean in swift when there is a period bewteen two variables and/or functions. I know it's very simple but I can't find an answer and it's driving me crazy. An example program is below:
“let string1 = "hello"
let string2 = " there"
var welcome = string1 + string2
// welcome now equals "hello there”
let exclamationMark: Character = "!"
welcome.append(exclamationMark)
// welcome now equals "hello there!”
Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks. https://itun.es/ca/jEUH0.l
What's the use of the period between welcome and append? What does it do?
Upvotes: 1
Views: 62
Reputation: 885
It's called "dot syntax" and that's what is used to access members, functions or properties of that instance.
Upvotes: 0
Reputation: 96
That's how you call function "append" for instance "welcome", passing "exclamationMark" as the parameter. In Objective-C this would be:
[welcome append: exclamationMark];
In general, the period is how you access any member (method or property) of an instance.
Upvotes: 1