I am very new to swift programming. I got stuck by the === operator in Swift. What is the basic use of identical operator (===) in Swift.
Asked
Active
Viewed 1,338 times
1 Answers
4
===
is the identity operator, which tests if two variables refer to the same instance.
The equality operator ==
only tests if two objects are equal.
You can test the following code in a Playground:
let str1 = NSURL(string: "http://www.google.com")
let str2 = str1
let str3 = NSURL(string: "http://www.google.com")
str1 == str2 // true
str1 == str3 // true
str1 === str2 // true
str1 === str3 // false

Glorfindel
- 21,988
- 13
- 81
- 109