Kodeco Forums

iCloud and UIDocument: Beyond the Basics, Part 3/4

This is a blog post by site administrator Ray Wenderlich, an independent software developer and gamer. Welcome back to our document-based iCloud app tutorial series! In this tutorial series, we are making a complete document-based iCloud app called PhotoKeeper, with features that go beyond just the basics. In the first and second parts of the […]


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/2920-icloud-and-uidocument-beyond-the-basics-part-3-4

This is an extremely useful quartet of tutorials - many thanks! The “correct” iCloud rename functionality is broken, as noted in the tutorial, which is a shame, as the rest is truly excellent. The rename code (sorry it’s in Swift) should look like this…

    let fileManager = FileManager()
    let coordinator = NSFileCoordinator(filePresenter: nil)
    // Wrap in file coordinator
    OperationQueue().addOperation {
        coordinator.coordinate(writingItemAt: oldURL, options: NSFileCoordinator.WritingOptions.forMoving, writingItemAt: newURL, options: NSFileCoordinator.WritingOptions.forReplacing, error: nil, byAccessor: 
    {               
            coordinator.item(at: oldURL, willMoveTo: newURL)
            do {
                try fileManager.moveItem(at: $0, to: $1)
                coordinator.item(at: oldURL, didMoveTo: newURL)
                self.localisedName = newName
                OperationQueue.main.addOperation { // For UI Update
                    self.updateTitle()
                }
            } catch {
                print("Failed to move to \(newURL)")
            }
        })
    }

Hey all,

Just finished up part 3 of the this series. I’ve been converting all the code to Swift and all of the functionality seems to be working with one caveat. So, between one device and the simulator, the data appears to be syncing on both. However, the photos are not coming through on both devices. Any thoughts? Or an area of the code that would be most a most likely culprit to share to help troubleshoot?

Best!

This tutorial is more than six months old so questions are no longer supported at the moment for it. We will update it as soon as possible. Thank you! :]