• 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
Re: Proper way to create a singleton without @synchronized ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Proper way to create a singleton without @synchronized ?


  • Subject: Re: Proper way to create a singleton without @synchronized ?
  • From: Joanna Carter <email@hidden>
  • Date: Mon, 18 Apr 2011 18:46:45 +0100

Hi Steven

> How? If you don't have an instantiation of the class you don't have
> anywhere to store the data.
> Either I am misunderstanding what you are saying or you are missing my
> suggestion of class methods.
> Perhaps you could explain?

// StaticClass.h
@interface StaticClass : NSObject
{
}

+ (NSManagedObjectContext *) managedObjectContext;

@end

//StaticClass.m
@implementation StaticClass

static NSManagedObjectContext *managedObjectContext = nil;

+ (NSManagedObjectContext *) managedObjectContext
{
  if (!managedObjectContext)
  {

    … // create and setup

  }
  return managedObjectContext;
}

@end


This can then be accessed from other code as…

{
  NSManagedObjectContext *context = [StaticClass managedObjectContext];

  …
}

Joanna

--
Joanna Carter
Carter Consulting

_______________________________________________

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

  • Prev by Date: Dynamic UTIs and 10.6 NSPasteboard APIs
  • Next by Date: Resolving a crash address to position in code
  • Previous by thread: Re: Proper way to create a singleton without @synchronized ?
  • Next by thread: AVFoundation -- Authorization for Playback of Protected Content?
  • Index(es):
    • Date
    • Thread