1

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?

1
  • 1
    In the "A Swift Tour" chapter of the same book: "Use dot syntax to access the properties and methods of the instance." Commented Jul 6, 2015 at 14:07

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

It's called "dot syntax" and that's what is used to access members, functions or properties of that instance.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.