How do I create a NSArray of NSString constants?
How do I create a NSArray of NSString constants?
- Subject: How do I create a NSArray of NSString constants?
- From: Scott Mitchell <email@hidden>
- Date: Mon, 27 Jun 2005 10:31:57 -0600
Ok this may sound weird but here is what I need to do.
I need to create a constant NSArray of string constants that I have. So
for example I have
NSString* GB_Submit_Period1 = @"GB_Submit_Period1";
NSString* GB_Submit_Period2 = @"GB_Submit_Period2";
NSString* GB_Submit_Period3 = @"GB_Submit_Period3";
NSString* GB_Submit_Period4 = @"GB_Submit_Period4";
NSString* GB_Submit_Period5 = @"GB_Submit_Period5";
NSString* GB_Submit_Period6 = @"GB_Submit_Period6";
NSString* GB_Submit_Period7 = @"GB_Submit_Period7";
NSString* GB_Submit_Period8 = @"GB_Submit_Period8";
NSString* GB_Submit_Period9 = @"GB_Submit_Period9";
NSString* GB_Submit_Period10 = @"GB_Submit_Period10";
NSString* GB_Submit_Period11 = @"GB_Submit_Period11";
NSString* GB_Submit_Period12 = @"GB_Submit_Period12";
and each of the @"<strings above>" is defined in my Localizable.strings
file. But what I really need to do is to create an NSArray of these
strings. So for example something like this
NSArray* GB_Period_Number_Strings_Array = {@"GB_Submit_Period1",
@"GB_Submit_Period2", @"GB_Submit_Period3", @"GB_Submit_Period4",
@"GB_Submit_Period5", @"GB_Submit_Period6", @"GB_Submit_Period7",
@"GB_Submit_Period8", @"GB_Submit_Period9", @"GB_Submit_Period10",
@"GB_Submit_Period11", @"GB_Submit_Period12" };
So I can access these strings whenever I need them, based on there
position in the array. I seem to get complier warnings when I try this
above:
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:338: warning:
initialization from incompatible pointer type
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:338: warning:
excess elements in scalar initializer
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:338: warning:
(near initialization for `GB_Period_Number_Strings_Array')
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:338: warning:
excess elements in scalar initializer
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:338: warning:
(near initialization for `GB_Period_Number_Strings_Array')
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:338: warning:
excess elements in scalar initializer
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:338: warning:
(near initialization for `GB_Period_Number_Strings_Array')
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:338: warning:
excess elements in scalar initializer
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:338: warning:
(near initialization for `GB_Period_Number_Strings_Array')
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:338: warning:
excess elements in scalar initializer
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:338: warning:
(near initialization for `GB_Period_Number_Strings_Array')
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:339: warning:
excess elements in scalar initializer
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:339: warning:
(near initialization for `GB_Period_Number_Strings_Array')
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:339: warning:
excess elements in scalar initializer
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:339: warning:
(near initialization for `GB_Period_Number_Strings_Array')
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:339: warning:
excess elements in scalar initializer
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:339: warning:
(near initialization for `GB_Period_Number_Strings_Array')
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:339: warning:
excess elements in scalar initializer
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:339: warning:
(near initialization for `GB_Period_Number_Strings_Array')
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:339: warning:
excess elements in scalar initializer
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:339: warning:
(near initialization for `GB_Period_Number_Strings_Array')
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:339: warning:
excess elements in scalar initializer
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:339: warning:
(near initialization for `GB_Period_Number_Strings_Array')
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:338:
warning: initialization from incompatible pointer type
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:338:
warning: excess elements in scalar initializer
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:338:
warning: (near initialization for `GB_Period_Number_Strings_Array')
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:338:
warning: excess elements in scalar initializer
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:338:
warning: (near initialization for `GB_Period_Number_Strings_Array')
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:338:
warning: excess elements in scalar initializer
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:338:
warning: (near initialization for `GB_Period_Number_Strings_Array')
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:338:
warning: excess elements in scalar initializer
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:338:
warning: (near initialization for `GB_Period_Number_Strings_Array')
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:338:
warning: excess elements in scalar initializer
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:338:
warning: (near initialization for `GB_Period_Number_Strings_Array')
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:339:
warning: excess elements in scalar initializer
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:339:
warning: (near initialization for `GB_Period_Number_Strings_Array')
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:339:
warning: excess elements in scalar initializer
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:339:
warning: (near initialization for `GB_Period_Number_Strings_Array')
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:339:
warning: excess elements in scalar initializer
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:339:
warning: (near initialization for `GB_Period_Number_Strings_Array')
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:339:
warning: excess elements in scalar initializer
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:339:
warning: (near initialization for `GB_Period_Number_Strings_Array')
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:339:
warning: excess elements in scalar initializer
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:339:
warning: (near initialization for `GB_Period_Number_Strings_Array')
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:339:
warning: excess elements in scalar initializer
/Users/scottmitchell/gradebook/Main Sources/GBConstants.m:339:
warning: (near initialization for `GB_Period_Number_Strings_Array')
What am I doing wrong here? Can I not create a constant NSArray like
this? If not then how can I accomplish what I want to do, without going
to a switch statement to choose the correct localized NSString or
something like that?
Any help would be appreciated.
Thanks,
Scott Mitchell
Macintosh Software Engineer
Excelsior Software
http://www.excelsiorsoftware.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden