Last active
April 27, 2020 02:21
-
-
Save GOROman/85ae3a9528279aec51e32ab600773fc4 to your computer and use it in GitHub Desktop.
iOSでiCloud Driveにアクセスする方法(Swift)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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