Re: didPrint selector not called
Re: didPrint selector not called
- Subject: Re: didPrint selector not called
- From: Jeremy Hughes <email@hidden>
- Date: Fri, 16 Dec 2016 21:10:50 +0000
> This is what I’ve currently got. It works OK, but the dictionary conversion seems clunky to me.
>
> override func printDocument(sender: AnyObject?)
> {
> let didPrintSelector = #selector(document(_:didPrint:contextInfo:))
>
> let dictionary = printInfo.dictionary()
> var printSettings = [String : AnyObject]()
>
> for key in printInfo.dictionary().allKeys
> {
> if let string = key as? String
> {
> printSettings[string] = dictionary.valueForKey(string)
> }
> }
>
> printDocumentWithSettings(printSettings, showPrintPanel: true, delegate: self, didPrintSelector: didPrintSelector, contextInfo: nil)
> }
If I cast the NSMutableDictionary to an NSDictionary, I can recast that to a Swift dictionary:
override func printDocument(sender: AnyObject?)
{
let didPrintSelector = #selector(document(_:didPrint:contextInfo:))
let printSettings = (printInfo.dictionary() as NSDictionary) as! [String : AnyObject]
printDocumentWithSettings(printSettings, showPrintPanel: true, delegate: self, didPrintSelector: didPrintSelector, contextInfo: nil)
}
Is this a general thing? If I want to cast an NSMutableType to a Swift Type I have to cast it to an NSType first?
Maybe it's changed in Swift 3 (I’m still on 2.2) but I haven’t found any Apple documentation about this.
Jeremy
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden