Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > How to re-use page setup info?

How to re-use page setup info?
Thread Tools
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Dec 10, 2002, 05:15 PM
 
How do I get an (Objective C) application to remember the page setup that was used last time?

I'm trying to do this:

Code:
[[NSUserDefaults standardUserDefaults] setObject:[NSPrintInfo sharedPrintInfo] forKey:@"page_setup"];
But that produces the error:

Code:
-[NSUserDefaults setObject:forKey:]: Attempt to insert non-property value '{<blah blah blah>}' of class 'NSPrintInfo'.
(except with lots of page setup data insetead of "<blah blah blah>")

What is the correct way of doing this?
     
Brass  (op)
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Dec 10, 2002, 05:20 PM
 
I think I've just found the answer to the question myself. In the documentation:

There are a couple cases where you may want to record the settings of a print info object. First, you may want to remember the print settings used the last time your application was run. In this case you could record the print info object as an application preference each time the user prints something and then restore the settings when the application launches. However, because the dictionary that stores an NSPrintInfo object's print settings includes non-property list values, it is not a proper property list object. Therefore, it cannot be converted to a plist format and saved directly as a preference value. Instead, you need to use the NSKeyedArchiver (or NSArchiver) class method archivedDataWithRootObject: to encode the NSPrintInfo object as an NSData object, which can be stored in a property list or saved to a file. To restore the NSPrintInfo object, reload the NSData object and then use the NSKeyedUnarchiver (or NSUnarchiver) class method unarchiveObjectWithData: to decode the NSPrintInfo information.
     
Brass  (op)
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Dec 10, 2002, 05:26 PM
 
Yep, that works nicely with:

Code:
[[NSUserDefaults standardUserDefaults] setObject:[NSArchiver archivedDataWithRootObject:[NSPrintInfo sharedPrintInfo]] forKey:@"page_setup"];
I guess I had the right idea at the beginning, but just needed a little more refinement.

...I love talking to myself...
     
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
Dec 10, 2002, 08:39 PM
 
Also, standard Mac OS convention has always been to save Page Setup info on a per-document basis. Saving it in NSUserDefaults is okay for a non-document-based app, or if you want to create a Page Setup for new documents, but if you're a document-based app you should be using NSArchiver to save it in your document files.
Rick Roe
icons.cx | weblog
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 01:56 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2