初始化 CGContext
Initialize CGContext
我正在尝试初始化 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:)
let url = NSURL.fileURL(withPath: documentsPath + "/datafile") as CFURLRef
let context = CGPDFContextCreateWithURL(url, nil, nil)
我正在尝试初始化 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:)
let url = NSURL.fileURL(withPath: documentsPath + "/datafile") as CFURLRef
let context = CGPDFContextCreateWithURL(url, nil, nil)