Vote count:
0
I have this function:
func removeCloudURLAtIndexPath(indexPath: NSIndexPath!) {
if let documentURL = documentURLForIndexPath(indexPath) {
collectionView!.performBatchUpdates({
var mutableDocumentURLs = NSMutableArray(array: self.documentURLs)
mutableDocumentURLs.removeObject(documentURL)
self.documentURLs = NSArray(array: mutableDocumentURLs)
self.collectionView!.deleteItemsAtIndexPaths([indexPath])
},
completion: { (success: Bool) -> Void in
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), { () -> Void in
let fileCoordinator = NSFileCoordinator(filePresenter: nil)
var fileCoordinationError: NSError?
fileCoordinator.coordinateWritingItemAtURL(documentURL, options: NSFileCoordinatorWritingOptions.ForDeleting, error: &fileCoordinationError, byAccessor: { newURL in
if fileCoordinationError != nil {
println("File coord error: \(fileCoordinationError)")
}
println("Deleting item at url \(newURL)")
var removeError: NSError?
NSFileManager.defaultManager().removeItemAtURL(newURL, error: &removeError)
if removeError != nil {
println("Remove error: \(removeError)")
}
})
})
self.collectionView!.reloadData()
})
}
}
which is called like this:
func didSelectTrashButton(button: UIBarButtonItem) {
if isEditing {
for indexPath in selectedIndexPaths {
removeCloudURLAtIndexPath(indexPath)
}
}
isEditing = false
}
But for some reason, my iCloud query adds it back to my model because it doesn’t get deleted properly. There are no errors printed from removeCloudURLAtIndexPath
so I don’t have much to go on other than syntax, or, if I’m overlooking something which should/shouldn't be there.
In case it’s needed, here is the method my iCloud query notification calls:
func metadataQueryDidUpdate(notification: NSNotification) {
iCloudQuery.disableUpdates()
var newDocumentURLs = NSMutableArray()
println("New results: \(iCloudQuery.results)")
for result in iCloudQuery.results {
if let metaDataItem = result as? NSMetadataItem {
if let itemURL = metaDataItem.valueForAttribute(NSMetadataItemURLKey) as? NSURL {
if !newDocumentURLs.containsObject(itemURL) {
newDocumentURLs.addObject(itemURL)
}
}
}
}
println("New document URLs from update: \(newDocumentURLs)")
documentURLs = newDocumentURLs
iCloudQuery.enableUpdates()
}
asked 1 min ago
Removing a document from iCloud (Swift)
Aucun commentaire:
Enregistrer un commentaire