• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Trouble with NSUserDefaults extension class
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Trouble with NSUserDefaults extension class


  • Subject: Trouble with NSUserDefaults extension class
  • From: Bryan Hansen <email@hidden>
  • Date: Thu, 31 May 2007 10:42:08 -0700

I am trying to create an extension class for NSUserDefaults so that I can more easily store preference settings for a custom domain. I have created my class with 3 methods:

//  NSUserDefaults+MyExtensions.h

#import <Cocoa/Cocoa.h>

@interface NSUserDefaults (MyExtensions)

- (id)objectForKey:(NSString *)key forPersistentDomain:(NSString *) domain;
- (void)setObject:(id)anObject forKey:(NSString *)key forPersistentDomain:(NSString *)domain;
- (void)removeObjectForKey:(NSString *)key forPersistentDomain: (NSString *)domain;


@end

and then I have about 4 lines in each method that get, set and remove a key in whatever domain they pass in. The trouble is that I crash at runtime with the following error:

Main Thread Exception in Aperture: *** -[NSUserDefaults objectForKey:forPersistentDomain:]: selector not recognized [self = 0x110bf70]

when I use the [NSUserDefaults standardUserDefaults] object. If I init my own NSUserDefaults object it will pick up the my extensions, but I believe I should be using the [NSUserDefaults standardUserDefaults] for things to behave correctly.

Is there any reason why extensions are not working with the singleton instance, standardUserDefaults? Or is there a way to use my own init'ed NSUserDefaults object which won't differ from the standardUserDefaults?


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Trouble with NSUserDefaults extension class
      • From: Dominik Pich <email@hidden>
  • Prev by Date: Re: Jumpy unsynchronized movement with NSViewAnimation
  • Next by Date: Re: Trouble with NSUserDefaults extension class
  • Previous by thread: Re: strange NSButton background drawing issue - SOLVED
  • Next by thread: Re: Trouble with NSUserDefaults extension class
  • Index(es):
    • Date
    • Thread