
🪪 .id
❓UIKit은 따로 지정하지 않았는데?
AppKit과 UIKit에서는 Class를 사용하기 때문에 Pointer ID를 사용할 수 있지만,
SwiftUI는 Value Type이기 때문에 포인터를 사용할 수 없다.
Value Type에는 SwiftUI가 해당 View에 대한 지속적인 ID로 사용할 수 있는 정식 참조가 없다.
물론 SwiftUI도 항상 개발자가 지정하는 것은 아님, 밑에서 확인!!
🧩 역할
swiftUI는 view에게 identity를 부여해서 diffing을 통해 뷰를 구분 및 갱신한다.
.id modifier는 명시적(explicit)으로 id를 부여하는 역할이다.

당연히 Hashable한 값으로 넣어줘야함
🧐 .id를 지정하지 않는다면?
swiftUI는 기본적으로 구조적 아이덴티티(structural identity)를 통해서 view의 identity로 사용한다.
View Hierarchy에서 Type과 위치에 따라 View를 구별한다.
✅ 목적
목적은 structural identity를 무시하고 강제로 view를 업데이트하거나, id를 이용해 특정 위치로 이동하는 등
개발자가 식별자를 직접 지정해, 해당 뷰를 기준으로 여러 작업을 할 수 있게 도와준다.
출처
https://developer.apple.com/documentation/swiftui/view/id(_:)
id(_:) | Apple Developer Documentation
Binds a view’s identity to the given proxy value.
developer.apple.com
https://swiftwithmajid.com/2021/12/09/structural-identity-in-swiftui/
Structural identity in SwiftUI
Structural identity is the type of identity that SwiftUI uses to understand your views without an explicit identifier by using your layout description. This week we will learn how to improve performance and eliminate unwanted animations by using inert view
swiftwithmajid.com
https://developer.apple.com/videos/play/wwdc2021/10022/
Demystify SwiftUI - WWDC21 - Videos - Apple Developer
Peek behind the curtain into the core tenets of SwiftUI philosophy: Identity, Lifetime, and Dependencies. Find out about common patterns,...
developer.apple.com
'iOS > SwiftUI' 카테고리의 다른 글
| @NameSpace (0) | 2025.10.25 |
|---|---|
| PreferenceKey (0) | 2025.10.24 |
| containerRelativeFrame (0) | 2025.10.23 |
| SwiftUI 동작 방식 (0) | 2025.10.18 |
| textContentType (0) | 2025.10.03 |