티스토리 뷰
강의를 듣다가 문득 CollectionView나 TableView의 cell을 나타낼때,
indexPath.row / indexPath.item
나눠 사용하는 코드를 봤는데 무슨 차이일까 궁금해서 공부를 해봤습니다.
가시죱
거기에 대한 답변이 잘나와있는 부분을 가져왔어요.
밑줄친 내용을 보면
가독성을 위해 나누어 놨다고 이해하면 되겠네요.
스타일상 UICollectionView에서는 item을,
UITableView에서는 row를 사용하는게 더 깔끔한 방식이긴 합니다. (암묵적인 약속..)
하지만 tableview에서 item을 사용해도, collectionview에서 row를 사용해도 아무 문제 없습니다.
참고
1. https://developer.apple.com/forums/thread/123050
IndexPath.row V.S. IndexPath.item? | Apple Developer Forums
They're functionally the same, but I recommend that you use them only as intended. That's because they're objects, and that in turn mean that instances passed to you (by table views or collections, etc) may be subclasses that only implement one or other of
developer.apple.com
2. https://medium.com/@b0661064248/indexpath-item-vs-row-1f8cb3f658d9
IndexPath & item vs row
IndexPath
medium.com
'iOS' 카테고리의 다른 글
[Swift] 익스텐션 (Extensions) (0) | 2022.07.01 |
---|---|
[Swift] 중첩 타입 (Nested Types) (0) | 2022.06.24 |
[Swift] ARC (Automatic Reference Counting) (0) | 2022.06.19 |
[Swift] NSCache, 이미지캐시 개념 (0) | 2022.06.17 |
[iOS] APNs (Apple Push Notification service) (0) | 2022.06.10 |
- Total
- Today
- Yesterday
- Swift Leetcode
- 원티드 프리온보딩
- Swift 프로그래머스
- Swift
- Class
- CS 네트워크
- Swift 알고리즘
- Swift joined()
- swift 고차함수
- Swift joined
- swift protocol
- Swift final
- ios
- Swift ModernRIBs
- RIBs tutorial
- Swift RIBs
- RTCCameraVideoCapturer
- Swift init
- iOS error
- Swift Error Handling
- swift reduce
- swift property
- 2023년 회고
- Combine: Asynchronous Programming with Swift
- Swift 프로퍼티
- swift programmers
- Swift inout
- Swift 내림차순
- swift (programmers)
- removeLast()
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |