• 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: Create an NSCharacterSet constant
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Create an NSCharacterSet constant


  • Subject: Re: Create an NSCharacterSet constant
  • From: Kyle Sluder <email@hidden>
  • Date: Sun, 1 Nov 2009 21:29:25 -0800

On Sun, Nov 1, 2009 at 9:19 PM, John Joyce
<email@hidden> wrote:
> Is it possible to create an NSCharacterSet constant?

No.  By definition, constants are assigned values at compile time.
Objects other than strings can only be created at runtime.  There is
no way around this fact.

> Is it best just to declare a global constant string, then initialize an
> NSCharacterSet during app initialization? It certainly seems that is the
> only real option.

Answers will vary.  You could use a static global variable which is
assigned in +initialize, or you could use a static variable in a
category on NSCharacterSet, or a number of other things.  Basically
what you really want is a singleton, not a constant.

I'm partial to the following construct:

+ (Foo *)sharedFoo {
  static Foo *sharedFoo;
  dispatch_once_t once;
  dispatch_once(&once, ^{ sharedFoo = [[foo alloc] init]; }
  return sharedfoo;
}

--Kyle Sluder
_______________________________________________

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: Create an NSCharacterSet constant
      • From: Michael Ash <email@hidden>
References: 
 >Create an NSCharacterSet constant (From: John Joyce <email@hidden>)

  • Prev by Date: Create an NSCharacterSet constant
  • Next by Date: Re: Create an NSCharacterSet constant
  • Previous by thread: Create an NSCharacterSet constant
  • Next by thread: Re: Create an NSCharacterSet constant
  • Index(es):
    • Date
    • Thread