Here is the code that can perform the following functions in swift.
1: Check the weather catalog exists or not. if it does not exist, then create a directory (the directory provided the name of the application) in the document directory folder.
2: Now we have a catalog of applications. therefore, the entire file that the application will write / read to / from this directory.
let file = "file.txt" let directoryName = "XYZ" // Here "XYZ" is project name. var error : NSError? let filemgr = NSFileManager.defaultManager() let dirPaths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true) let documentsDirectory = dirPaths[0] as! String var dataPath = documentsDirectory.stringByAppendingPathComponent(directoryName) if !NSFileManager.defaultManager().fileExistsAtPath(dataPath) { NSFileManager.defaultManager().createDirectoryAtPath(dataPath, withIntermediateDirectories: false, attributes: nil, error: &error) } else { println("not creted or exist") }
Now we have a directory, so you only need to write / read data from the directory.
how to write a file to a document directory in swift
let filePath = dataPath.stringByAppendingPathComponent(file); let text = "some text" //writing text.writeToFile(filePath, atomically: false, encoding: NSUTF8StringEncoding, error: nil);
How to read a file from a document directory.
let filePath = dataPath.stringByAppendingPathComponent(file); // Read file let text2 = String(contentsOfFile: filePath, encoding: NSUTF8StringEncoding, error: nil)
Output: 
Hope this helps you.
source share