How to save default printer in UserDefaults in Swift?

This is the workflow of my application: The user can select the default printer on the application settings page and will use this default printer to print directly each time without any preview dialog .

We can select a printer using UIPrinterPickerController:

let printerPicker = UIPrinterPickerController(initiallySelectedPrinter: nil)
printerPicker.present(from: CGRect(x: 0, y: 0, width: 600, height: 500), in: self, animated: true) { (printerPicker, userDidSelect, error) in
    if userDidSelect {
        //Here get the selected UIPrinter
        let defaultPrinter = printerPicker.selectedPrinter
    }
}

Upon receipt, UIPrinterwe cannot directly store the object UIPrinterin UserDefaults, which is not a type of support for UserDefault.

Are there other save options UIPrinterin UserDefaults or any other way to keep the printer as default.

+4
source share
1 answer

NSKeyedArchiver. , , NSCoding.

UIPrinter NSUserDefaults. . :

UIPrinter NSUserDefaults. , URL- , , UIPrinter, URL- NSUserDefaults UIPrinter printerWithURL:.

+2

Source: https://habr.com/ru/post/1692704/


All Articles