I have a simple function that create pdf file and return its path.
func createPDFFileAndReturnPath() -> String {
let fileName = "pdffilename.pdf"
let paths = NSSearchPathForDirectoriesInDomains(.LibraryDirectory, .UserDomainMask, true)
let documentsDirectory = paths[0]
let pathForPDF = documentsDirectory.stringByAppendingString("/" + fileName)
UIGraphicsBeginPDFContextToFile(pathForPDF, CGRectZero, nil)
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, 100, 400), nil)
let text = "text" //how to print this in whatever place?
//text.drawInRect - this doesn't work
UIGraphicsEndPDFContext()
return pathForPDF
}
Sebastian's Answer - Updated for Swift 4.2