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 > Help with Aaron Hillegass Chapter 10 Challenge

Help with Aaron Hillegass Chapter 10 Challenge
Thread Tools
Forum Regular
Join Date: Aug 2005
Status: Offline
Reply With Quote
Feb 16, 2006, 06:57 PM
 
I am guessing a few people have read his book and might be able to help me out with this challenge. For those who have not read the book, the challenge is to add a button to a preference panel to reset the values in the NSUserDefaults standardUserDefaults "BNREmptyDocKey" and "BNRTableBgColorKey" keys. One is a stores data for a collorWell, and the other for a checkbox. This is the code that I came up with, that just doesn't work . I get a warning, "Warning: passing argument 1 of 'registerDefaults:' from distinct Objective-C type". Anyone have an idea how this is supposed to work?

- (IBAction)resetDefaultsid)sender
{
NSUserDefaults *defaults;
defaults = [NSUserDefaults standardUserDefaults];
[defaults removeObjectForKey:@"BNREmptyDocKey"];
[defaults removeObjectForKey:@"BNRTableBgColorKey"];
[[NSUserDefaults standardUserDefaults] registerDefaults:defaults];
}
YummySoup! - Recipe management and sharing at its best!
     
ntt
Fresh-Faced Recruit
Join Date: Jul 2003
Location: Seattle, WA
Status: Offline
Reply With Quote
Feb 16, 2006, 09:29 PM
 
You are passing registerDefaults: an argument that is a NSUserDefaults object, but it expects an NSDictionary.

Look at the API here:
http://developer.apple.com/documenta...isterDefaults:

edit: i should also add that you can just edit the user defaults directly...
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"keyname"];
http://bestbits.ii.net/ for widgets and more
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Feb 16, 2006, 09:51 PM
 
I don't think registerDefaults: is what you want at all. That sets default settings — what will be used if the user hasn't changed any settings. It won't override preferences. You want to edit the standardUserDefaults as ntt suggested.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
   
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 09:29 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