Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- SeSAC
- ios
- ribs
- combinecocoa
- Tuist Swift
- swift db
- Subscribe
- swift
- observable
- GCD
- Combine
- Swift Tuist
- Firebase Analytics
- arc
- ios database
- Subject
- 카카오뱅크 ios
- Tuist
- 네트워크 통신
- Firebase
- RxSwift
- KeyPath
- SwiftUI
- swift 5.9
- realm
- swift 6
- JSON
- xcode
- swift database
- uitableviewdiffabledatasource
Archives
- Today
- Total
천원의 개발
IOS Firebase에서 데이터 가져오기 본문
db.collection("컬렉션 이름")
.order("정렬할 필드 선택")
.addSnapshotListener { querySnapshot, error in
self.messages = [] // message 배열 초기화
if let e = error{ // 에러 관리
print("There was an issue retrieveing data from Firestore. \(e)")
} else{
if let snapshotDocuments = querySnapshot?.documents {
for doc in snapshotDocuments{
let data = doc.data() // data를 dictionary구조로 받아옴
if let messageSender = data["sender필드"] as? String, let messageBody = data["바디 필드"] as? String{
let newMessage = Message(sender: messageSender, body: messageBody)
self.messages.append(newMessage)
DispatchQueue.main.async {
self.tableView.reloadData()
}
}
}
}
}
}
'iOS&Swift🍎' 카테고리의 다른 글
iOS Privacy Manifest (1) | 2024.04.29 |
---|---|
IOS ObservableObject (0) | 2022.05.19 |
IOS Firebase에 데이터 추가 하기 (0) | 2022.04.02 |
IOS TableView 커스텀 (0) | 2022.03.31 |
IOS TableView 초기설정 (0) | 2022.03.30 |