본문 바로가기

개발

[Realm] Realm 에서 primaryKey id 이용해서 가장 마지막 데이터 가져오기

Realm db 사용 중에 가장 최근에 생성된 마지막 데이터를 가져와야 할 때가 있는데 번번이 까먹어서 정리해둔다.

  if let lastDate = self.realm?.objects(PlanModel.self).max(by: { $0.id < $1.id }) {
                          lastPlanDate = lastDate.dateID
                      }