• 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: Graham Cox <email@hidden>
  • Date: Mon, 2 Nov 2009 16:32:49 +1100


On 02/11/2009, at 4:19 PM, John Joyce wrote:

Is it possible to create an NSCharacterSet constant?
Attempting to do so with the methods for creating an NSCharacterSet naturally fails to compile with "initializer element is not constant"
I would ideally like to be able to do this.
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.
Am I missing something?
If I am correct in what I am seeing, would there not be a valid use case for this as an extension of NSCharacterSet?


You can't create any non-scalar constant (except nil) using a static initializer.

However, what you want to do is super-easy, and yes, it's a case for an extension to NSCharacterSet. Just add a class method as a category:

@interface NSCharacterSet (MyCharacterSetConstant)

+ (NSCharacterSet*)		theConstantCharacterSet;

@end


@implementation NSCharacterSet (MyCharacterSetConstant)

+ (NSCharacterSet*)		theConstantCharacterSet
{
    static NSCharacterSet* s_tccs = nil;

if( s_tccs == nil )
s_tccs = [[self characterSetWithCharactersInString:@"..."] retain];


    return s_tccs;
}



@end


--Graham


_______________________________________________

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

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