你如何设置范围:NSView中的NSRangePointer知道Swift中的PageRange?

How do you set range: NSRangePointer in NSView knowsPageRange in Swift?

我正在尝试使用 knowsPageRange 函数在 NSView 中设置打印页数。如何正确设置范围:NSRangePointer?

override func knowsPageRange(_ range: NSRangePointer) -> Bool {
    let printOperation = NSPrintOperation.current!
    let printInfo: NSPrintInfo = printOperation.printInfo

    // Where can I draw?
    pageRect = printInfo.imageablePageBounds
    let newFrame = NSRect(origin: CGPoint(), size: printInfo.paperSize)
    frame = newFrame

    // Construct the range to return
    var rangeOut = NSRange(location: 0, length: 0)

    // Pages are 1-based. That is, the first page is 1.
    rangeOut.location = 1
    rangeOut.length = 10 // Number of pages

    // Return the newly constructed range, rangeOut, via the range pointer
    range.memory = rangeOut // Cannot assign to property: 'range' is a 'let' constant

    return true
}

只需更改:

range.memory = rangeOut

至:

range.pointee = rangeOut

pointee的使用来自Swift3.memory来自Swift2.