for line in lines {
let panel = NSSavePanel()
panel.nameFieldStringValue = "\(counter++).txt"
if panel.runModal() == NSOKButton {
let pathURL = panel.directoryURL!.URLByAppendingPathComponent("\(panel.nameFieldStringValue)")
if NSFileManager.defaultManager().isWritableFileAtPath(pathURL.path!) {
line.writeToURL(pathURL, atomically: false, encoding: NSUTF8StringEncoding, error: nil)
} else {
let alert = NSAlert()
alert.messageText = "Unable to save \(pathURL.path!)\nError: Permission denied"
alert.runModal()
}
}
}
text.componentsSeparatedByString / text.componentsSeparatedByCharacterSet
let dir = "/Users/username/Documents"
let dir = "~/Documents".stringByExpandingTildeInPath