├── AppDelegate.swift ├── Assets.xcassets ├── AccentColor.colorset │ └── Contents.json ├── AppIcon.appiconset │ └── Contents.json └── Contents.json ├── Base.lproj ├── LaunchScreen.storyboard └── Main.storyboard ├── Info.plist ├── README.md ├── SceneDelegate.swift ├── ViewController.swift ├── iClodeDemo.entitlements └── iClodeManager.swift /AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // iClodeDemo 4 | // 5 | // Created by mac-00021 on 15/06/21. 6 | // 7 | 8 | import UIKit 9 | 10 | @main 11 | class AppDelegate: UIResponder, UIApplicationDelegate { 12 | 13 | 14 | 15 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 16 | // Override point for customization after application launch. 17 | return true 18 | } 19 | 20 | // MARK: UISceneSession Lifecycle 21 | 22 | func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { 23 | // Called when a new scene session is being created. 24 | // Use this method to select a configuration to create the new scene with. 25 | return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) 26 | } 27 | 28 | func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { 29 | // Called when the user discards a scene session. 30 | // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. 31 | // Use this method to release any resources that were specific to the discarded scenes, as they will not return. 32 | } 33 | 34 | 35 | } 36 | 37 | -------------------------------------------------------------------------------- /Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "scale" : "1x", 46 | "size" : "20x20" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "scale" : "2x", 51 | "size" : "20x20" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "scale" : "1x", 56 | "size" : "29x29" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "scale" : "2x", 61 | "size" : "29x29" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "scale" : "1x", 66 | "size" : "40x40" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "scale" : "2x", 71 | "size" : "40x40" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "scale" : "1x", 76 | "size" : "76x76" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "scale" : "2x", 81 | "size" : "76x76" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "scale" : "2x", 86 | "size" : "83.5x83.5" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "scale" : "1x", 91 | "size" : "1024x1024" 92 | } 93 | ], 94 | "info" : { 95 | "author" : "xcode", 96 | "version" : 1 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UIApplicationSceneManifest 24 | 25 | UIApplicationSupportsMultipleScenes 26 | 27 | UISceneConfigurations 28 | 29 | UIWindowSceneSessionRoleApplication 30 | 31 | 32 | UISceneConfigurationName 33 | Default Configuration 34 | UISceneDelegateClassName 35 | $(PRODUCT_MODULE_NAME).SceneDelegate 36 | UISceneStoryboardFile 37 | Main 38 | 39 | 40 | 41 | 42 | UIApplicationSupportsIndirectInputEvents 43 | 44 | UILaunchStoryboardName 45 | LaunchScreen 46 | UIMainStoryboardFile 47 | Main 48 | UIRequiredDeviceCapabilities 49 | 50 | armv7 51 | 52 | UISupportedInterfaceOrientations 53 | 54 | UIInterfaceOrientationPortrait 55 | 56 | UISupportedInterfaceOrientations~ipad 57 | 58 | UIInterfaceOrientationPortrait 59 | UIInterfaceOrientationPortraitUpsideDown 60 | UIInterfaceOrientationLandscapeLeft 61 | UIInterfaceOrientationLandscapeRight 62 | 63 | 64 | NSUbiquitousContainers 65 | 66 | iCloud.com.mi.CloudTest 67 | 68 | NSUbiquitousContainerIsDocumentScopePublic 69 | 70 | NSUbiquitousContainerName 71 | com.mi.CloudTest 72 | NSUbiquitousContainerSupportedFolderLevels 73 | Any 74 | 75 | 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # iCloud Document Storage 2 | 3 | iCloud Drive is Apple's essential connection between all your devices, Mac, iPhone, iPad, even your Windows PC.While the cost of storage seems expensive in comparison to other online storage services, its advantage is that it works natively across all your devices. 4 | 5 | ![alt text](https://cdn-images-1.medium.com/max/800/1*iZHl-IXaow5Ts7VOwCaS8Q.png) 6 | 7 | In this iCloud tutorial, you'll learn how to create folder and add files in iCloud from your app as well as how to move and copy files from Local to iCloud and Vice versa. 8 | 9 | You can download source code at end of this blog. 10 | 11 | Let's see how to do it 🙂 12 | 13 | # Setting up iCloud Storage APIs 14 | Let's start by creating a new project for iOS. 15 | 16 | You can select the single view application template. 17 | In this tutorial we're not going to touch the UIDocument class at all. 🤷‍♂️ 18 | 19 | ![alt text](https://cdn-images-1.medium.com/max/1200/1*hPpJ-D94n5ZdWJis_ZBYyw.png) 20 | 21 | The first step is to enable iCloud capabilities, which will generate a new entitlements file in your project. Also you'll have to enable the iCloud application service for the app id on the Apple developer portal. You should also assign the iCloud container that's going to be used to store data. you have to do this manually. 22 | 23 | #### Note: You need a valid Apple Developer Program membership in order to set advanced app capabilities like iCloud support. So you have to pay $99/year🤑 24 | 25 | The next step is to modify the Info.plist. I would recommend selecting "Open As" option and use "Source Code" so you can work with pretty standard XML. 26 | 27 | ![alt text](https://cdn-images-1.medium.com/max/800/1*bKw8cJgeg_8pmBndhv-ULg.png) 28 | 29 | Read brief article on [Medium](https://medium.com/@parth.gohel/icloud-document-storage-d338cf745076) 30 | -------------------------------------------------------------------------------- /SceneDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SceneDelegate.swift 3 | // iClodeDemo 4 | // 5 | // Created by mac-00021 on 15/06/21. 6 | // 7 | 8 | import UIKit 9 | 10 | class SceneDelegate: UIResponder, UIWindowSceneDelegate { 11 | 12 | var window: UIWindow? 13 | 14 | 15 | func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { 16 | // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. 17 | // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. 18 | // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). 19 | guard let _ = (scene as? UIWindowScene) else { return } 20 | } 21 | 22 | func sceneDidDisconnect(_ scene: UIScene) { 23 | // Called as the scene is being released by the system. 24 | // This occurs shortly after the scene enters the background, or when its session is discarded. 25 | // Release any resources associated with this scene that can be re-created the next time the scene connects. 26 | // The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead). 27 | } 28 | 29 | func sceneDidBecomeActive(_ scene: UIScene) { 30 | // Called when the scene has moved from an inactive state to an active state. 31 | // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. 32 | } 33 | 34 | func sceneWillResignActive(_ scene: UIScene) { 35 | // Called when the scene will move from an active state to an inactive state. 36 | // This may occur due to temporary interruptions (ex. an incoming phone call). 37 | } 38 | 39 | func sceneWillEnterForeground(_ scene: UIScene) { 40 | // Called as the scene transitions from the background to the foreground. 41 | // Use this method to undo the changes made on entering the background. 42 | } 43 | 44 | func sceneDidEnterBackground(_ scene: UIScene) { 45 | // Called as the scene transitions from the foreground to the background. 46 | // Use this method to save data, release shared resources, and store enough scene-specific state information 47 | // to restore the scene back to its current state. 48 | } 49 | 50 | 51 | } 52 | 53 | -------------------------------------------------------------------------------- /ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // iClodeDemo 4 | // 5 | // Created by mac-00021 on 15/06/21. 6 | // 7 | 8 | import UIKit 9 | import CloudKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /iClodeDemo.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.developer.icloud-container-identifiers 6 | 7 | iCloud.com.mi.CloudTest 8 | 9 | com.apple.developer.icloud-services 10 | 11 | CloudDocuments 12 | 13 | com.apple.developer.ubiquity-container-identifiers 14 | 15 | iCloud.com.mi.CloudTest 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /iClodeManager.swift: -------------------------------------------------------------------------------- 1 | // 2 | // iClodeManager.swift 3 | // iClodeDemo 4 | // 5 | // Created by mac-00021 on 15/06/21. 6 | // Developer Name: Parth Gohel 7 | 8 | import Foundation 9 | 10 | class CloudDataManager { 11 | 12 | static let shared = CloudDataManager() // Singleton 13 | 14 | let fileManager = FileManager.default 15 | 16 | struct DocumentsDirectory { 17 | static var localDocumentsURL: URL? { 18 | return FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! 19 | } 20 | static var iCloudDocumentsURL: URL? { 21 | return FileManager.default.url(forUbiquityContainerIdentifier: nil)?.appendingPathComponent("Documents") 22 | } 23 | } 24 | 25 | // Return the Document directory (Cloud OR Local) 26 | // To do in a background thread 27 | func getDocumentDiretoryURL() -> URL { 28 | 29 | debugPrint("======================= Document paths =======================") 30 | debugPrint("iCloud Directory: \(String(describing: DocumentsDirectory.iCloudDocumentsURL?.path))") 31 | debugPrint("Local Directory: \(String(describing: DocumentsDirectory.localDocumentsURL?.path))") 32 | 33 | if self.isCloudEnabled() { 34 | return DocumentsDirectory.iCloudDocumentsURL! 35 | } else { 36 | return DocumentsDirectory.localDocumentsURL! 37 | } 38 | } 39 | 40 | //// Return true if iCloud is enabled 41 | func isCloudEnabled() -> Bool { 42 | if DocumentsDirectory.iCloudDocumentsURL != nil { return true } 43 | else { 44 | debugPrint("iCloud is not enabled") 45 | return false 46 | } 47 | } 48 | 49 | func isFileExist(at path: String) -> Bool{ 50 | return FileManager.default.fileExists(atPath: path, isDirectory: nil) 51 | } 52 | 53 | //create subdirectory in iCloud 54 | func createSubdirectory(folderName: String){ 55 | guard isCloudEnabled() else {return} 56 | 57 | let nestedFolderURL = DocumentsDirectory.iCloudDocumentsURL!.appendingPathComponent(folderName) 58 | if self.isFileExist(at: nestedFolderURL.path){ 59 | debugPrint("!!!!!! Folder already exist !!!!!!") 60 | return 61 | }else{ 62 | do{ 63 | let _ = try FileManager.default.createDirectory( 64 | at: nestedFolderURL, 65 | withIntermediateDirectories: false, 66 | attributes: nil 67 | ) 68 | debugPrint("\(folderName) is created sussceefully") 69 | } catch { 70 | debugPrint("Can't create a folder") 71 | } 72 | } 73 | } 74 | 75 | func createTextFileInDirectry(folderName: String, 76 | filename: String){ 77 | guard self.isCloudEnabled() else {return} 78 | 79 | let nestedFolderURL = DocumentsDirectory.iCloudDocumentsURL!.appendingPathComponent(folderName) 80 | 81 | if !self.isFileExist(at: nestedFolderURL.path){ 82 | debugPrint("\(folderName) is not found at \(DocumentsDirectory.iCloudDocumentsURL!)") 83 | } 84 | let fullname = filename + ".txt" 85 | let fileUrl = nestedFolderURL.appendingPathComponent(fullname) 86 | do { 87 | try "Hello iCloud!".write(to: fileUrl, atomically: true, encoding: .utf8) 88 | debugPrint("Write successfully in the file") 89 | } 90 | catch { 91 | print(error.localizedDescription) 92 | } 93 | } 94 | 95 | //// Delete all files at URL 96 | // 97 | func deleteFilesInDirectory(url: URL,filenameWithExtension: String = "") { 98 | if filenameWithExtension.isEmpty{ 99 | let enumerator = self.fileManager.enumerator(atPath: url.path) 100 | while let file = enumerator?.nextObject() as? String { 101 | do { 102 | if !self.isFileExist(at: url.appendingPathComponent(file).path){ 103 | debugPrint("!!!!! File is not exist !!!!") 104 | return 105 | } 106 | try fileManager.removeItem(at: url.appendingPathComponent(file)) 107 | print("!!! \(file) deleted !!!") 108 | } catch let error as NSError { 109 | print("!!! Failed deleting files : \(error) !!!") 110 | } 111 | } 112 | debugPrint("All files deleted") 113 | }else{ 114 | if !self.isFileExist(at: url.appendingPathComponent(filenameWithExtension).path){ 115 | debugPrint("file is not exist") 116 | return 117 | } 118 | debugPrint("Deleting........") 119 | do { 120 | try fileManager.removeItem(at: url.appendingPathComponent(filenameWithExtension)) 121 | print("\(filenameWithExtension) deleted") 122 | } catch let error as NSError { 123 | print("Failed deleting files : \(error)") 124 | } 125 | } 126 | 127 | } 128 | 129 | func fetchListOfFiles(at urlPath: String = DocumentsDirectory.iCloudDocumentsURL?.path ?? ""){ 130 | guard self.isCloudEnabled(), 131 | !urlPath.isEmpty else { 132 | debugPrint("!!! Path is empty !!!") 133 | return 134 | } 135 | 136 | let enumerator = self.fileManager.enumerator(atPath: urlPath) 137 | 138 | debugPrint("!!!!================== All Files ===================!!!!") 139 | while let file = enumerator?.nextObject() as? String { 140 | debugPrint(file) 141 | } 142 | } 143 | 144 | // Move iCloud files to local directory 145 | // Local dir will be cleared 146 | // No data merging 147 | 148 | func moveFileToLocal(fileName: String = "", 149 | withExtension: String = "", 150 | copyToLocal: Bool = false) { 151 | guard self.isCloudEnabled() else {return} 152 | 153 | if fileName.isEmpty && withExtension.isEmpty{ 154 | let enumerator = fileManager.enumerator(atPath: DocumentsDirectory.iCloudDocumentsURL!.path) 155 | while let file = enumerator?.nextObject() as? String { 156 | debugPrint(file) 157 | do { 158 | //Note: When you try to send the file to iCloud you should set the flag to true. you where using false which is to remove the file from iCloud. 159 | if copyToLocal{ 160 | try self.fileManager.copyItem(at: DocumentsDirectory.iCloudDocumentsURL!.appendingPathComponent(file), to: DocumentsDirectory.localDocumentsURL!.appendingPathComponent(file)) 161 | debugPrint("Copy to local dir \(DocumentsDirectory.localDocumentsURL!.appendingPathComponent(file))") 162 | }else{ 163 | try fileManager.setUbiquitous(false, 164 | itemAt: DocumentsDirectory.iCloudDocumentsURL!.appendingPathComponent(file), 165 | destinationURL: DocumentsDirectory.localDocumentsURL!.appendingPathComponent(file)) 166 | debugPrint("Moved to local dir \(DocumentsDirectory.localDocumentsURL!.appendingPathComponent(file))") 167 | } 168 | 169 | 170 | } catch let error as NSError { 171 | debugPrint("Failed to move file to local dir : \(error)") 172 | } 173 | } 174 | }else{ 175 | 176 | var fullName: String = "" 177 | 178 | if withExtension.isEmpty{ 179 | fullName = fileName 180 | }else{ 181 | fullName = fileName+withExtension 182 | } 183 | 184 | if !self.isFileExist(at: DocumentsDirectory.iCloudDocumentsURL!.appendingPathComponent(fullName).path){ 185 | debugPrint("\(fullName) not exist") 186 | return 187 | } 188 | do { 189 | //Note: When you try to send the file to iCloud you should set the flag to true. you where using false which is to remove the file from iCloud. 190 | if copyToLocal{ 191 | try fileManager.copyItem(at: DocumentsDirectory.iCloudDocumentsURL!.appendingPathComponent(fullName), to: DocumentsDirectory.localDocumentsURL!.appendingPathComponent(fullName)) 192 | debugPrint("Copy to local dir \(DocumentsDirectory.localDocumentsURL!.appendingPathComponent(fullName))") 193 | }else{ 194 | try fileManager.setUbiquitous(false, 195 | itemAt: DocumentsDirectory.iCloudDocumentsURL!.appendingPathComponent(fullName), 196 | destinationURL: DocumentsDirectory.localDocumentsURL!.appendingPathComponent(fullName)) 197 | debugPrint("Moved to local dir \(DocumentsDirectory.localDocumentsURL!.appendingPathComponent(fullName))") 198 | 199 | } 200 | } catch let error as NSError { 201 | debugPrint("Failed to move file to local dir : \(error)") 202 | } 203 | } 204 | 205 | } 206 | 207 | //// Move/copy iCloud files to local directory 208 | //// Local dir will be cleared 209 | //// No data merging 210 | 211 | func moveFileToCloud(fileName: String, 212 | withExtension: String, 213 | copyToCloud:Bool = false) { 214 | guard self.isCloudEnabled() else {return} 215 | 216 | if fileName.isEmpty && withExtension.isEmpty{ 217 | let enumerator = fileManager.enumerator(atPath: DocumentsDirectory.localDocumentsURL!.path) 218 | while let file = enumerator?.nextObject() as? String { 219 | debugPrint(file) 220 | do { 221 | //Note: When you try to send the file to iCloud you should set the flag to true. you where using false which is to remove the file from iCloud. 222 | if copyToCloud{ 223 | try fileManager.copyItem(at: DocumentsDirectory.localDocumentsURL!.appendingPathComponent(file), to: DocumentsDirectory.iCloudDocumentsURL!.appendingPathComponent(file)) 224 | debugPrint("Copy to icloud dir \(DocumentsDirectory.iCloudDocumentsURL!.appendingPathComponent(file))") 225 | }else{ 226 | try fileManager.setUbiquitous(true, 227 | itemAt:DocumentsDirectory.localDocumentsURL!.appendingPathComponent(file) , 228 | destinationURL:DocumentsDirectory.iCloudDocumentsURL!.appendingPathComponent(file)) 229 | debugPrint("Moved to icloud dir \(DocumentsDirectory.iCloudDocumentsURL!.appendingPathComponent(file))") 230 | } 231 | 232 | 233 | 234 | } catch let error as NSError { 235 | print("Failed to move file to Cloud : \(error)") 236 | } 237 | } 238 | }else{ 239 | 240 | var fullName: String = "" 241 | 242 | if withExtension.isEmpty{ 243 | fullName = fileName 244 | }else{ 245 | fullName = fileName+withExtension 246 | } 247 | 248 | if !self.isFileExist(at: DocumentsDirectory.localDocumentsURL!.appendingPathComponent(fullName).path){ 249 | debugPrint("\(fullName) not exist") 250 | return 251 | } 252 | do { 253 | //Note: When you try to send the file to iCloud you should set the flag to true. you where using false which is to remove the file from iCloud. 254 | debugPrint(fullName) 255 | if copyToCloud{ 256 | try self.fileManager.copyItem(at: DocumentsDirectory.localDocumentsURL!.appendingPathComponent(fullName), 257 | to: DocumentsDirectory.iCloudDocumentsURL!.appendingPathComponent(fullName)) 258 | debugPrint("Copy to icloud dir \(DocumentsDirectory.iCloudDocumentsURL!.appendingPathComponent(fullName))") 259 | }else{ 260 | try self.fileManager.setUbiquitous(true, 261 | itemAt:DocumentsDirectory.localDocumentsURL!.appendingPathComponent(fullName) , 262 | destinationURL:DocumentsDirectory.iCloudDocumentsURL!.appendingPathComponent(fullName)) 263 | debugPrint("Moved to icloud dir \(DocumentsDirectory.iCloudDocumentsURL!.appendingPathComponent(fullName))") 264 | } 265 | } catch let error as NSError { 266 | print("Failed to move file to Cloud : \(error)") 267 | } 268 | } 269 | } 270 | } 271 | 272 | --------------------------------------------------------------------------------