//source by.
//https://www.mongodb.com/docs/realm/sdk/swift/crud/filter-data/
let highPriorityTasks = tasks.where {
$0.priority > 5
}
print("High-priority tasks: \(highPriorityTasks.count)")
let longRunningTasks = tasks.where {
$0.progressMinutes >= 120
}
print("Long running tasks: \(longRunningTasks.count)")
let unassignedTasks = tasks.where {
$0.assignee == nil
}
print("Unassigned tasks: \(unassignedTasks.count)")
//NSPredicate Quary
let predicate = NSPredicate(format: "progressMinutes > 1 AND name == %@", "Ali")
// Use [c] for case-insensitivity.
let startWithE = projects.filter("name BEGINSWITH[c] 'e'")
print("Projects that start with 'e': \(startWithE.count)")
let containIe = projects.filter("name CONTAINS 'ie'")
print("Projects that contain 'ie': \(containIe.count)")
// [d] for diacritic insensitivty: contains 'e', 'E', 'é', etc.
let containElike = projects.filter("name CONTAINS[cd] 'e'")
print("Projects that contain 'e', 'E', 'é', etc.: \(containElike.count)")
필터 예시
@objc func filterButton() {
//스트링 내 문자 필터링
tasks = localRealm.objects(ShopList.self).filter("title CONTAINS '1'")
//스트링 기반 필터링
tasks = localRealm.objects(ShopList.self).filter("title = '18_안녕하세요'")
}
@objc func sortButton() {
tasks = localRealm.objects(ShopList.self).sorted(byKeyPath: "regiDate", ascending: true)
}
//좌 -> 우 스와이프
func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let favorite = UIContextualAction(style: .normal, title: "즐겨찾기") { action, view, completionHandler in
print("favorite Button Clicked")
}
let example = UIContextualAction(style: .normal, title: "예시") { action, view, completionHandler in
print("example Button Clicked")
}
return UISwipeActionsConfiguration(actions: [favorite, example])
//UIContextualAction -> 각 아이템
}
//반대
//leadingSwipeActions -> trailingSwipeActions
-결과
try! self.localRealm.write {
//하나의 레코드에서 특정 컬럼 하나만 변경
self.tasks[indexPath.row].favorite = !self.tasks[indexPath.row].favorite
//해당 indexPath.row의 favorite만 변경
//Update1.
//하나의 테이블에 특정 컬럼 전체 값을 변경
//self.tasks.setValue(true, forKey: "favorite")
//모든 favorite 변경
//Update2.
//하나의 레코드에서 여러 컴럼들이 변경
//self.localRealm.create(ShopList.self, value: ["objectID": self.tasks[indexPath.row].objectID, "title": "변경테스트"], update: .modified)
//2가지 이상 컬럼 변경
}
-얼럿 or 액션시트 or UIMenu
-TableView Delegate, DataSource
ex.
lazy var tableView: UITableView = {
let view = UItableView()
//delegate, datasource 선언은 테이블 뷰 변수 선언과 동시에 사용 불가
//지연 저장을 통하여 초기화 이후에 실행되도록 명명
view.delegate = self
view.datasource = self
.
.
.
}
-StackView
ex.
lazy var stackView: UIStackView = {
let view = UIStackView(arrnagedSubviews: [뷰1, 뷰2, 뷰3, ..., 뷰n])
}
[SeSAC] 20220822_TIL (Realm) (0) | 2022.08.22 |
---|---|
[SeSAC] 20220816_TIL (Custom Framework, Access Control, UIView Animation, PageViewController) (0) | 2022.08.16 |
[SeSAC] 20220811_TIL (Privacy & Authorization, 권한, Apple Map, MapKit) (0) | 2022.08.11 |
[SeSAC] 20220809_TIL (TableView + CollectionView) (0) | 2022.08.09 |
[SeSAC] 20220808_TIL (API관련 파일 관리하기) (0) | 2022.08.08 |