、私はあなたがpdfファイルを持っていることを、ここで仮定していますデータ。
特定のディレクトリ内のDocumentDirectoryにファイルを格納するには、ディレクトリが存在するかどうかを確認する必要があります(存在しない場合)。
var path = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]
do {
path = path.stringByAppendingFormat("/Dir1/Dir2")
if (!NSFileManager.defaultManager().fileExistsAtPath(path)) {
try NSFileManager.defaultManager().createDirectoryAtPath(path, withIntermediateDirectories: true, attributes: nil)
}
//Now write the data of pdf file here
path = path.stringByAppendingFormat("/Filename.pdf")
let data = NSData() //Here data is NSData of your pdf file
try data.writeToFile(path, options: .DataWritingAtomic)
}
catch let error as NSError {
print(error.localizedDescription)
}
@AMomchilov私は実際にそれを理解しました。私は単に文字列に別のディレクトリを追加する必要があります。例 - let Path = documentsDirectory.stringByAppendingPathComponent( "Path1/SubPath1 /") –
これは私が疑ったものです。この質問へのあなたの答えを提出し、それを受け入れてください – Alexander