.id

2025. 10. 23. 23:30·iOS/SwiftUI
반응형

 

🪪 .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
'iOS/SwiftUI' 카테고리의 다른 글
  • @NameSpace
  • PreferenceKey
  • containerRelativeFrame
  • SwiftUI 동작 방식
Hamp
Hamp
남들에게 보여주기 부끄러운 잡다한 글을 적어 나가는 자칭 기술 블로그입니다.
  • Hamp
    Hamp의 분리수거함
    Hamp
  • 전체
    오늘
    어제
    • 분류 전체보기 (304)
      • CS (30)
        • 객체지향 (2)
        • Network (7)
        • OS (6)
        • 자료구조 (1)
        • LiveStreaming (3)
        • 이미지 (1)
        • 잡다한 질문 정리 (0)
        • Hardware (2)
        • 이론 (6)
        • 컴퓨터 그래픽스 (0)
      • Firebase (3)
      • Programing Langauge (37)
        • swift (32)
        • python (4)
        • Kotlin (1)
      • iOS (132)
        • UIKit (37)
        • Combine (1)
        • SwiftUI (32)
        • Framework (7)
        • Swift Concurrency (22)
        • Tuist (6)
        • Setting (11)
        • Modularization (1)
        • Instruments (6)
      • PS (59)
        • 프로그래머스 (24)
        • 백준 (13)
        • LeetCode (19)
        • 알고리즘 (3)
      • Git (18)
        • 명령어 (4)
        • 이론 (2)
        • hooks (1)
        • config (2)
        • action (7)
      • Shell Script (2)
      • Linux (6)
        • 명령어 (5)
      • Spring (13)
        • 어노테이션 (1)
        • 튜토리얼 (11)
      • CI-CD (4)
      • Android (0)
        • Jetpack Compose (0)
  • 블로그 메뉴

    • 홈
    • 태그
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    프로그래머스
    protocol
    lifecycle
    투포인터
    SwiftUI
    백준
    dfs
    dp
    dispatch
    Tuist
    UIKit
    concurrency
    property
    Swift
    AVFoundation
    GIT
    boostcamp
    IOS
    Spring
    CS
  • 최근 댓글

  • 최근 글

  • 반응형
  • hELLO· Designed By정상우.v4.10.0
Hamp
.id
상단으로

티스토리툴바