• 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
singleton design pattern
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

singleton design pattern


  • Subject: singleton design pattern
  • From: Alejandro Marcos Aragón <email@hidden>
  • Date: Tue, 18 May 2010 17:28:26 -0500

Hi all,

I've been staring at this piece of code now to try to find out what's wrong with it and I can't think of anything at this point. I'm trying to have a single instance of an NSMutableDictionary inside a class:



// in .h file
@interface ClassA : NSObject {

}

+ (NSMutableDictionary*) uniqueInstance;

@end

// in .m file
@implementation ClassA


+ (NSMutableDictionary*) uniqueInstance {

	static NSMutableDictionary* uniqueInstance = nil;

	if (uniqueInstance == nil) {

	// directory to save files
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *dir = [paths objectAtIndex:0];

	NSFileManager *fileManager = [NSFileManager defaultManager];

	NSString *customFilePath = [[NSString alloc] initWithString:
								[dir stringByAppendingPathComponent:@"dict.plist"]];

		  uniqueInstance = [[NSMutableDictionary alloc] initWithContentsOfFile:customFilePath];
	}

	return  uniqueInstance;
}


I can't use this code because there is a EXC_BAD_ACCESS according to the debugger.

I tried moving the definition of the uniqueInstance outside the function and that didn't help. This code seems alright to me, but I can't find why it doesn't work. Can someone point out the problem?

aa

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please 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: singleton design pattern
      • From: Mike Abdullah <email@hidden>
  • Prev by Date: Re: NSTask and piped commands
  • Next by Date: Re: singleton design pattern
  • Previous by thread: Re: NSKeyedArchiver: confusion
  • Next by thread: Re: singleton design pattern
  • Index(es):
    • Date
    • Thread