How can you implement the NSDocument method -canCloseDocumentWithDelegate:shouldCloseSelector:contextInfo: in Swift?

后端 未结 4 1442
粉色の甜心
粉色の甜心 2021-01-13 07:25

In my application, a NSDocument subclass mission-critical hardware – users really don’t want to close a document by accident! So, I’ve implemented canClos

4条回答
  •  旧时难觅i
    2021-01-13 08:05

    Here is a Swift solution to this issue that I received from Apple Developer Technical Support:

    override func canCloseDocumentWithDelegate(delegate: AnyObject, shouldCloseSelector: Selector, contextInfo: UnsafeMutablePointer) {
        super.canCloseDocumentWithDelegate(self, shouldCloseSelector: "document:shouldClose:contextInfo:", contextInfo: contextInfo)
    }
    
    func document(doc:NSDocument, shouldClose:Bool, contextInfo:UnsafeMutablePointer) {
        if shouldClose {
            // 
            doc.close()
        }
    }
    

提交回复
热议问题