FREE TRIAL: Accelerate your app development career with 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?


Hacking with Swift is sponsored by Sentry

SPONSORED With Sentry’s error and performance monitoring for iOS you see mobile vitals that actually matter, can solve any latency issues quickly, and learn how each release is performing over time.

Get started

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.