1
내 응용 프로그램에서 CloudKit에 문제가 있습니다. 처음에 뷰를로드하면 데이터가 완벽하게로드됩니다. 그러나 "새로 고침"을하면 "치명적인 오류가 발생합니다 : 색인이 범위를 벗어났습니다". 이상한 것은 코드에 차이가 없다는 것입니다 (적어도 나를 위해). 새로 고침 할 때 "수행"되지 않습니다 ("B"가 인쇄되지 않음). 디버거에 오류가 표시되지 않습니다.CloudKit perform
실마리가 있습니까?
미리 감사드립니다.
니코
의 viewDidLoad :
loadCloudData()
handlePullToRefresh :
func handlePullToRefresh() {
loadCloudData()
}
loadCloudData :
func loadCloudData() {
DispatchQueue.main.async {
self.showMessage(titleText: NSLocalizedString("Loading ...", comment: "SwiftMessage Loading Title"), text: NSLocalizedString("Loading PixelCodes from Cloud", comment: "SwiftMessage Loading Title"), backgroundColor: UIColor.tileYellow(), textColor: UIColor.darkGray, image: #imageLiteral(resourceName: "cloud"))
}
dataCloud = [CKRecord]()
let query = CKQuery(recordType: PixelCodeType.recordType, predicate: NSPredicate(format: "TRUEPREDICATE", argumentArray: nil))
query.sortDescriptors = [NSSortDescriptor(key: "title", ascending: true)]
print("A")
databasePublic.perform(query, inZoneWith: nil) { (results:[CKRecord]?, error:Error?) in
print("B")
if error != nil {
print("PixelCode from Cloud not Loaded!\n\(error!.localizedDescription)")
self.couldLoadCloadData = false
DispatchQueue.main.async {
SwiftMessages.hideAll()
if self.refreshControl != nil {
if self.refreshControl!.isRefreshing {
self.refreshControl!.endRefreshing()
}
}
//"Cloud" active
self.segmentedControl.setEnabled(true, forSegmentAt: 1)
}
self.handleError(title: NSLocalizedString("Error!", comment: "SwiftMessage error title"), text: error!.localizedDescription, errorTitle: "Cloud Loading Error:loadCloudData()", error: error)
} else {
if let data = results {
print("pixelCodes updated")
self.dataCloud = data
if results!.isEmpty {
self.couldLoadCloadData = true
self.isCloudDataLoaded = false
} else {
self.couldLoadCloadData = true
self.isCloudDataLoaded = true
}
self.uploadTimes()
DispatchQueue.main.async {
if self.refreshControl != nil {
if self.refreshControl!.isRefreshing {
self.refreshControl!.endRefreshing()
}
}
SwiftMessages.hideAll()
//"Cloud" active
self.segmentedControl.setEnabled(true, forSegmentAt: 1)
self.tableView.reloadData()
}
}
}
}
}
"dataCloud = [CKRecord]()"가 제거되었으며 모든 것이 잘 작동합니다! 왜 내가 그것을 제거하지 않을지 모르겠다. 고마워요 !!! –