Swift와 Firebase로 채팅 응용 프로그램을 만드는 방법에 대해 잠시 후에 Udemy의 강좌에 등록했습니다. 단순히 어떻게 작동하는지에 대한 통찰력을 얻고 싶었 기 때문입니다.Swift 3 Firebase 업데이트 코드 변환 - 정렬
그러나 일주일 후에 과정을 마쳤습니다. 이것은 몇 달 전이었고, 그 후로는 Firebase와 Swift에 대한 업데이트가 있었고 현재 일부 오래된 코드를 새로운 코드로 변환하는 데 어려움을 겪고 있습니다. 그래서 내가 단순히 날짜, 오름차순 통해 정렬 오전있는 tableView, 모든 "채팅"을 표시하는 코드는 단순히
func loadRecents() {
firebase.child("Recent").queryOrdered(byChild: "userId").queryEqual(toValue: FIRAuth.auth()!.currentUser?.uid).observe(.value) { (snapshot:FIRDataSnapshot) in
self.recents.removeAll()
if snapshot.exists() {
if let values = snapshot.value as? [String:AnyObject] {
let sorted = (values as! NSArray).sortedArray(using: [NSSortDescriptor(key: "date", ascending: false)])
for recent in sorted {
self.recents.append(recent as! NSDictionary)
self.conversationTableView.reloadData()
}
}
self.conversationTableView.reloadData()
}
self.conversationTableView.reloadData()
}
self.checkUnread()
}
: 여기
내가 현재 고민하고있는 코드입니다 거짓입니다.내가 변경 한 사항은 이전 snapshot.value.allValues
을 snapshot.value as? [String:AnyObject]
으로 간단히 변환하는 것입니다. 쿼리는 로그인 한 계정 (FIRAuth.auth().currentUser!.uid)
으로 정렬됩니다.
그러나이 코드를 작성할 때마다 오류가 발생하므로이 코드는 더 이상 사용되지 않습니다. 그리고 이전 버전에서 작동한다는 사실을 알고 있습니다.
: 여기에 전체 이전 코드입니다Thread 1: EXC_BAD_INSTRUCTION
그리고이 필요하며, 경우 내가 (될 수 있음) 완전히 현재 코드를 엉망 것을 발생합니다
이
오류입니다func loadRecents() {
firebase.child("Recent").queryOrderedByChild("userId").queryEqualToValue(FIRAuth.auth()!.currentUser!.uid).observeEventType(.Value, withBlock: {
snapshot in
self.recents.removeAll()
if snapshot.exists() {
let sorted = (snapshot.value!.allValues as NSArray).sortedArrayUsingDescriptors([NSSortDescriptor(key: "date", ascending: false)])
for recent in sorted {
self.recents.append(recent as! NSDictionary)
//add functio to have offline access as well, this will download with user recent as well so that we will not create it again
firebase.child("Recent").queryOrderedByChild("chatRoomID").queryEqualToValue(recent["chatRoomID"]).observeEventType(.Value, withBlock: {
snapshot in
})
}
}
self.tableView.reloadData()
})
self.checkUnread()
}
어떻게 우회할지/해결할 지에 대한 아이디어가 있으십니까? 도움말 크게 감사드립니다.
이상하게도 문제가 해결되지 않은 것 같습니다. 음 .. – askaale