Created
May 20, 2022 11:43
-
-
Save developer-shubham101/ceb1b8fc661eaedf0a0e6af138573ba7 to your computer and use it in GitHub Desktop.
Swift Triple Equals example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// TripleEqualsExampleViewController.swift | |
// UpgradeMySelf-ios | |
// | |
// Created by Shubham Sharma on 09/05/22. | |
// Copyright © 2022 Shubham Sharma. All rights reserved. | |
// | |
import UIKit | |
class TripleEqualsExample : Equatable { | |
let value: Int | |
init(value: Int) { | |
self.value = value | |
} | |
static func == (lhs: TripleEqualsExample, rhs: TripleEqualsExample) -> Bool { | |
return lhs.value == rhs.value | |
} | |
} | |
class TripleEqualsExampleViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
self.view.backgroundColor = .white | |
///Triple Equals check that both object's reference is same or not. | |
let instances1 = TripleEqualsExample(value: 5) | |
let instances2 = TripleEqualsExample(value: 5) | |
let instances3 = instances1 | |
if instances1 == instances2 { | |
print("the two instances are equal!") | |
} | |
if instances1 === instances2 { | |
//It does not enter here | |
} else { | |
print("the two instances are not identical!") | |
} | |
if instances3 === instances1 { | |
print("the two instances are identical!") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment