Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does .text and the dot mean in Swift? [duplicate]

Tags:

swift

I am currently coding my own app and I was looking at a coding video for help and the person in the video was using .text and some other things that had dots in front of them like .color and .shape, which were variables declared and initialized already. I was wondering if anybody has a clear definition on what the .text means or what it does and what the overall dot means whenever you use it.

like image 679
Adarsh Kotlapati Avatar asked Jan 02 '23 23:01

Adarsh Kotlapati


1 Answers

This feature is called "Implicit Member Expression"

An implicit member expression is an abbreviated way to access a member of a type, such as an enumeration case or a class method, in a context where type inference can determine the implied type. It has the following form:

.member name

For example : if you want to pick a color, in Swift4 you can simply do so:

let color: UIColor = .green

instead of typing :

let color : UIColor = UIColor.green()
like image 169
Madhur Avatar answered Jan 05 '23 16:01

Madhur