【发布时间】:2016-01-02 14:51:11
【问题描述】:
我正在执行此函数以保存启用和禁用 iCloud 的 UIDocument,但我似乎错过了两次抛出。特别是当iCloud被启用时,saveToURL返回false,我不知道为什么会这样,因为文档不是nil并且路径是合理的;这是我的简要功能:
func newFavorite(favorite: palinaModel) ->Bool {
if indexForPalina(favorite) != nil {
print("stop already favorite")
return false;
}
// Save Stop
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)
// Add Bookmark To Bookmarks
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
}
感谢您的支持。
【问题讨论】:
标签: swift icloud uidocument