ドキュメントディレクトリにpdfを作成し、ページ番号を付けたいので、CGPDFDocumentRefオブジェクトが必要です。
let fileName: NSString = "test.pdf"
let path:NSArray = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
let documentDirectory: AnyObject = path.objectAtIndex(0)
let pdfPathWithFileName = documentDirectory.stringByAppendingPathComponent(fileName as String)
UIGraphicsBeginPDFContextToFile(pdfPathWithFileName as String, CGRectZero, nil)
let ref : CGContextRef = UIGraphicsGetCurrentContext()!
let localUrl = NSURL.fileURLWithPath(pdfPathWithFileName)
URL のファイル パスを変換しましたが、この下の行でクラッシュが発生し、その理由がわかりません..?
let pdfDocumentRef: CGPDFDocumentRef = CGPDFDocumentCreateWithURL(localUrl as CFURLRef)!