> For the complete documentation index, see [llms.txt](https://krjaeh0.gitbook.io/j-log/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://krjaeh0.gitbook.io/j-log/programming/languages/swift-and-ios/swift-language-basics/classvsstructdifference.md).

# ClassVsStructDifference

#### 차이점 정리 표

| 특성      | Class                            | Struct             |
| ------- | -------------------------------- | ------------------ |
| 타입      | 참조 타입 (Reference Type)           | 값 타입 (Value Type)  |
| 상속      | 상속 가능                            | 상속 불가              |
| 인스턴스    | 하나의 인스턴스가 여러 참조 가능               | 각 변수에 독립적인 복사본 존재  |
| 생성자     | 사용자 정의 생성자 필요                    | 멤버와이즈 이니셜라이저 자동 제공 |
| 소멸자     | `deinit`을 사용하여 정리 가능             | 소멸자 없음             |
| ARC     | 자동 참조 카운팅에 의한 메모리 관리             | 참조 카운팅 없음          |
| 복사 시 동작 | 참조가 복사됨                          | 인스턴스 전체가 복사됨       |
| 메서드 변경  | `mutating` 키워드 없이 메서드에서 상태 변경 가능 | `mutating` 키워드 필요  |
| 프로토콜 적용 | 프로토콜 채택 가능                       | 프로토콜 채택 가능         |
| 예시      | UIViewController, UIView         | CGPoint, CGSize    |

#### 설명

{% stepper %}
{% step %}

### 타입

클래스는 참조 타입이므로, 변수에 클래스의 인스턴스를 할당하면 인스턴스의 참조가 할당됩니다.\
구조체는 값 타입이므로, 구조체의 인스턴스를 변수에 할당하면 인스턴스의 전체 복사본이 생성됩니다.
{% endstep %}

{% step %}

### 상속

클래스는 다른 클래스로부터 속성과 메서드를 상속받을 수 있지만, 구조체는 상속할 수 없습니다.
{% endstep %}

{% step %}

### 생성자와 소멸자

클래스는 사용자가 직접 생성자를 정의해야 하며, 필요에 따라 소멸자(`deinit`)를 구현할 수 있습니다.\
구조체는 모든 프로퍼티에 대한 초기값이 제공되면 자동으로 멤버와이즈 이니셜라이저를 제공합니다.
{% endstep %}

{% step %}

### 메모리 관리

클래스 인스턴스는 ARC에 의해 메모리 관리가 됩니다. 구조체는 ARC의 대상이 되지 않습니다.
{% endstep %}

{% step %}

### 메서드 변경

클래스의 메서드는 인스턴스 변수를 자유롭게 변경할 수 있습니다. 구조체의 메서드에서 변수를 변경하려면 `mutating` 키워드를 사용해야 합니다.
{% endstep %}
{% endstepper %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://krjaeh0.gitbook.io/j-log/programming/languages/swift-and-ios/swift-language-basics/classvsstructdifference.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
