# What's the difference between == and ===?

{% hint style="info" %}
타 언어에서도 항상 조심하는 부분 중 하나가 두 값의 비교이다.&#x20;
{% endhint %}

* [일반 타입(string, int, float, double, boolean) 비교](#string-int-float-double-boolean)
* [컬렉션 타입(Array, Set, Dictionary) 비교](#array-set-dictionary)
* [nil 비교](#nil)
* [Custom 타입 비교](#custom)

## 일반 타입(string, int, float, double, boolean) 비교

```swift
let value1 = 42
let value2 = 42

print(value1 == value2) // true
print(value1 === value2) // error: argument type 'Int' expected to be an instance of a class or class-constrained type
```

## 컬렉션 타입(Array, Set, Dictionary) 비교

```swift
let reference1 = ["key": "value"]
let reference2 = referenceDictionary1

print(reference1 == reference2) // true
print(reference1 === reference2) // true
```

## nil 비교

> 일반 타입(string, int, float, double, boolean) 비교와 같다

```swift
let nil1: String? = nil
let nil2: String? = nil

print(value1 == value2) // true
print(value1 === value2) // error: argument type 'String' expected to be an instance of a class or class-constrained type
```

## Custom 타입 비교

> Equatable Protocol을 준수해야한다

```swift
class IntegerRef: Equatable {
    let value: Int
    init(_ value: Int) {
        self.value = value
    }

    // 아래 부분이 없다면 Compile Error
    static func == (lhs: IntegerRef, rhs: IntegerRef) -> Bool {
        return lhs.value == rhs.value
    }
}

let value1 = IntegerRef(100)
let value2 = IntegerRef(100)

print(value1 == value2) // true
```

## 출처

* <https://developer.apple.com/documentation/swift/===(_:_:)>
* <https://developer.apple.com/documentation/swift/equatable>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://akk9132.gitbook.io/seungdeok-log/dev/app-frontend/whats-the-difference-between-and.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
