saveToURL in UIDocument returns false

I am executing a function to save an UIDocument both when iCloud is enabled and when it is not, but I seem to miss on both throws. In particular when iCloud is enabled saveToURL returns false, and I have no idea why it so, given the document is not nil and the path is apparently a reasonable one:

/private/var/mobile/Library/Mobile Documents/iCloud~com~information~inArrivo/Favorite/Stop_77082

this is my function in brief:

    func newFavorite(favorite: palinaModel) ->Bool {
        let baseURL = NSFileManager.defaultManager().URLForUbiquityContainerIdentifier(nil)
        var favoriteURL:NSURL!
        if (baseURL != nil) {
            let favoritesURL = baseURL!.URLByAppendingPathComponent(pathComponent())
            favoriteURL = favoritesURL.URLByAppendingPathComponent(String(format:"Stop_%@", favorite.palina))
        } else {
            let filePath = getFilePath()
            favoriteURL=NSURL(fileURLWithPath: filePath)
        }
        let document = FavoriteStopDocument(fileURL:favoriteURL, favorite:favorite)
        self.favoriteElements.append(document)
        print("favoriteUrl=" + favoriteURL.path!+" document="+document.favoriteStop!.palina)
        document.saveToURL(favoriteURL, forSaveOperation:.ForCreating, completionHandler:{(success) in
            if (success) {
                print("Save succeeded.");
            } else {
                print("Save failed.");
            }
        })
        return true
    }

I am using ICloud instead of CloudKit in order to continue supporting iOS 7, but most Swift tutorial are with the newer technology and so I am quite stuck. This function in particular is the translation from an objective-c one.


Thanks for you support.