UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

NSDocument data:ofType implementation when using NSPrintInfo

Forums > macOS

After having read Hacking with macOS I'm trying to develop another NSDocument based application. In my document (subclassed from NSDocument) I have a few properties, an enum, an int and an array of objects. The objects implement the NSCoding protocol as described in the chapter. The application also implements printing and so I would like to save/load the NSPrintInfo property (printInfo on the NSDocument base class).

My question is how should I implement my data:ofType function override to accompish saving:

  • printInfo from NSDocument
  • My local int and enum
  • My local array of NSCoding implementing objects

In the book, NSKeyedArchiver is used but this just creates a single NSData object from a given single root object, whereas I have multiple objects to store. I could create a new data object to hold all the properties I wish to store, but then how should I refer back to the printInfo property on NSDocument?

3      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.