[Swift] ๋ฐ˜๋ณต๋ฌธ์—์„œ id: \.id ์˜ ์˜๋ฏธ

    1. id ์•ž์— \. ์ด ๋ถ™๋Š” ์ด์œ , ๋ฐ˜๋ณต๋ฌธ์„ ์ด์šฉํ•ด์„œ ๋ฆฌ์ŠคํŠธ๋ฅผ ๋งŒ๋“ค๋•Œ Key๋ฅผ ์ฐธ์กฐํ•˜๋Š”๋ฒ• 

    List(landmarks, id: \.id) { landmark in
        LandmarkRow(landmark: landmark)
    }

     

    ํ•˜์ง€๋งŒ Landmark ์ฝ”๋“œ์— 

    struct Landmark: Hashable, Codable, Identifiable {

    ๋‹ค์Œ๊ณผ ๊ฐ™์ด Identifiable์„ ์ถ”๊ฐ€ํ•ด์ฃผ๋ฉด id key path๋Š” ์‚ญ์ œํ•ด๋„ ๋œ๋‹ค.  

    Identifiable ํ”„๋กœํ† ์ฝœ์„ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒฝ์šฐ id ํ”„๋กœํผํ‹ฐ๋ฅผ ์ง์ ‘ ์ง€์ •ํ•˜์ง€ ์•Š์•„๋„ List์—์„œ ์š”์†Œ๋ฅผ ์‹๋ณ„ํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋˜์–ด, key path๋ฅผ ๋”ฐ๋กœ ์ง€์ •ํ•  ํ•„์š”๊ฐ€ ์—†๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค! 

     

    List(landmarks) { landmark in
        LandmarkRow(landmark: landmark)
    }

     

    ๋ฐ˜์‘ํ˜•

    ๋Œ“๊ธ€