1

저는 이런식으로 주석을 달아서, 어느 파트가 눈에 쉽게 보이는지를 구성해왔습니다.
근데, 주석은.. 기껏해야 주절주절이기 때문에, 삭제하기로 했습니다.
또한, extension으로 구분하는 것도 없앴습니다.
2
func readNotification(index: Int) {
if notifications[index].status == .UnRead {
notifications[index].status = .Read
putNotificationReadStatus(notificationId: notifications[index].id)
}
}
알림을 읽지 않은 상태라면 읽음 처리를 하는 함수입니다.
들여쓰기를 없앨 수 있어서 없앴습니다.
func readNotification(index: Int) {
guard notifications[index].status == .UnRead else { return }
notifications[index].status = .Read
putNotificationReadStatus(notificationId: notifications[index].id)
}
3
func scrollViewDidReachBottom(cellIds: [Int64]) {
guard let lastId = notifications.last?.id, !isFetching else { return }
let isFetched = fetchedPages.contains(lastId)
if !isFetched && cellIds.contains(lastId) {
fetchNotifications(notificationId: lastId)
}
}
스크롤이 바닥에 닿았을 때, 추가로 api를 요청하는 함수입니다.
isFetched라는 변수는, 이미 해당 id로 호출한 기록을 확인하는 용도로 만든 변수인데, 차라리 fetchedPages.contains를 조건문에 직접 넣는게 읽기 편해보입니다.
func scrollViewDidReachBottom(cellIds: [Int64]) {
guard let lastId = notifications.last?.id, !isFetching else { return }
if !fetchedPages.contains(lastId) && cellIds.contains(lastId) {
fetchNotifications(notificationId: lastId)
}
}
isFetched 라는 변수가 fetchedPages에서 lastId를 포함하는지를 나타내는 변수구나 라고 인식하는 것보다
만약 fetchedPages가 lastId를 포함하지 않는다면 ... (중복이 없다면..)라고 인식하는게 자연스러울 것 같습니다.
'iOS > Refactoring' 카테고리의 다른 글
| [UIKit/Refactoring] 홈 화면 UX 개선하기 (리사이징, 메모리 캐싱) (0) | 2024.07.27 |
|---|---|
| [UIKit/Refactoring] MyPageProfileEditViewModel 코드 개선하기 (2) (0) | 2024.07.17 |
| [UIKit/Refactoring] MyPageProfileEditViewModel 코드 개선하기 (1) (0) | 2024.07.13 |
| [UIKit/Refactoring] CollectionView Dynamic Header 개선하기 (SupplementaryView) (0) | 2024.06.29 |
| [UIKit/Refactoring] getRelative... 코드 삭제 + 관련 문제 해결 (0) | 2024.06.24 |