-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feat] 최근 검색 이력 관리를 위한 Local DB - #2
- Loading branch information
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// LatestSearch.swift | ||
// Whidy-iOS | ||
// | ||
// Created by JinwooLee on 1/29/25. | ||
// | ||
|
||
import RealmSwift | ||
import Foundation | ||
|
||
final class LatestSearch: Object, ObjectKeyIdentifiable { | ||
@Persisted(primaryKey: true) var _id: ObjectId | ||
@Persisted var keyword: String | ||
@Persisted var regDt: Date = Date() | ||
} | ||
|
||
extension LatestSearch { | ||
// static을 사용해 타입 프로퍼티로 선언 | ||
// 여기서 선언한 realm을 사용해 저장, 삭제등을 진행한다. | ||
private static var realm = try! Realm() | ||
|
||
// realm객체에 값을 추가 | ||
static func addRow(_ search: LatestSearch) { | ||
try! realm.write { | ||
realm.add(search) | ||
} | ||
} | ||
|
||
// realm객체의 값을 삭제 | ||
static func delRow(_ search: LatestSearch) { | ||
try! realm.write { | ||
realm.delete(search) | ||
} | ||
} | ||
|
||
static func delRowAll() { | ||
try! realm.write { | ||
realm.deleteAll() | ||
} | ||
} | ||
} |