0

我正在尝试初始化 CGContext ( API )

let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
let url = NSURL.fileURL(withPath: documentsPath + "/datafile")
if let context = CGContext(url: url as CFURL) {
    // stuff      
}

但这给了我错误:

Cannot invoke initializer for type 'CGContext' with an argument list of type '(url: CFURL)'

我也试过CGContext(url as CFURL)CGContext.init(url as CFURL)

如果我添加mediaBox: nil我得到: Ambiguous reference to member 'init(data:width:height:bitsPerComponent:bytesPerRow:space:bitmapInfo:releaseCallback:releaseInfo:)

4

1 回答 1

1
let url = NSURL.fileURL(withPath: documentsPath + "/datafile") as CFURLRef    
let context = CGPDFContextCreateWithURL(url, nil, nil)
于 2017-06-21T09:19:24.633 回答