Skip to content

Instantly share code, notes, and snippets.

@GOROman
Last active April 27, 2020 02:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GOROman/85ae3a9528279aec51e32ab600773fc4 to your computer and use it in GitHub Desktop.
Save GOROman/85ae3a9528279aec51e32ab600773fc4 to your computer and use it in GitHub Desktop.
iOSでiCloud Driveにアクセスする方法(Swift)
func createDocumentsFolder() {
// iCloudコンテナのURL
let url = FileManager.default.url(forUbiquityContainerIdentifier: nil)
let path = (url?.appendingPathComponent("Documents"))!
do {
try FileManager.default.createDirectory(at: path, withIntermediateDirectories: true, attributes: nil)
} catch let error as NSError {
print(error)
}
// テキストファイルをつくってみる
let fileURL = getDocumentsPath("README.txt")
let todayText = "POWER TO MAKE YOUR DREAM COME TRUE."
if ( FileManager.default.fileExists( atPath: fileURL!.path ) == true ) {
} else {
do {
try todayText.write(to: fileURL!, atomically: true, encoding: .utf8)
}
catch {
print("write error")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment