I recently came across a piece of obj-C code that looked something like this:-
#import "LocationSeeker.h"
@interface LocationSeeker ()
@end
NSString *const LocationSeekerMapTypePrefKey= @"LocationSeekerMapTypePrefKey";
NSString *const CenterCoordinateLatitudePrefKey= @"CenterCoordinateLatitudePrefKey";
NSString *const CenterCoordinateLongitudePrefKey= @"CenterCoordinateLongitudePrefKey";
@implementation LocationSeeker
+(void)initialize{//used for making factory settings
NSLog(@"initializing custom factory settings");
//THE factory settings are not saved to disk.. These effect at runtime..
NSMutableDictionary *defaults= [NSMutableDictionary dictionary];
//Setting the default as Hybrid view for map
......
}
-(IBAction)buttonDidGetPressed:(id)sender{
NSLog(@"%@",NSStringFromSelector(_cmd));
NSLog(@"%@",sender);
[[NSUserDefaults standardUserDefaults] setInteger:[sender selectedSegmentIndex] forKey:WhereamiMapTypePrefKey];
if([sender selectedSegmentIndex]==0){
[worldView setMapType:MKMapTypeStandard];
}........
.....
}
In the code above, there are 3 constants declared at a global level. What i wanted to inquire was whether this is the correct place to declare and define globals. Shouldn't these be declared and defined inside @implementation LocationSeeker ? Like this:
#import "LocationSeeker.h"
@interface LocationSeeker ()
@end
@implementation LocationSeeker
NSString *const LocationSeekerMapTypePrefKey= @"LocationSeekerMapTypePrefKey";
NSString *const CenterCoordinateLatitudePrefKey= @"CenterCoordinateLatitudePrefKey";
NSString *const CenterCoordinateLongitudePrefKey= @"CenterCoordinateLongitudePrefKey";
+(void)initialize{//used for making factory settings
NSLog(@"initializing custom factory settings");
//THE factory settings are not saved to disk.. These effect at runtime..
NSMutableDictionary *defaults= [NSMutableDictionary dictionary];
//Setting the default as Hybrid view for map
......
}
What are the effects of the difference between the 2 approaches?