Gold challenge issue


#1

I’m trying to set two defaults; one as a factory setting (that would be part of register domain) and other as user level setting (part of application domain)…
Here are the constants-

NSString *const WhereamiMapTypePrefKey= @"WhereamiMapTypePrefKey"; NSString *const CenterCoordinatePrefKey= @"CenterCoordinatePrefKey";

This is factory setting implementation

[code]+(void)initialize{//used for making factory settings
NSLog(@“initializing custom factory settings”);
//THE factory settings are not saved to disk… These effect at runtime…

//Setting the default as Hybrid view for map
NSNumber *hybridViewNumber= [NSNumber numberWithInt:1];

//Setting a default coordinate
NSNumber *latitude=[NSNumber numberWithDouble:19.01761470];
NSNumber *longitude= [NSNumber numberWithDouble:72.85616440];

NSArray *coordData=@[latitude, longitude];
NSDictionary *defaults= @{CenterCoordinatePrefKey: coordData, WhereamiMapTypePrefKey:hybridViewNumber};
[[NSUserDefaults standardUserDefaults] registerDefaults];

}
[/code]

The user setting is recorded in foundLocation method

[code]//Setting user default in application domain…
NSNumber *latitude= [NSNumber numberWithFloat:coord.latitude];
NSNumber *longitude= [NSNumber numberWithFloat:coord.latitude];

NSArray *coordinateData= @[latitude,longitude];
[NSKeyedArchiver archivedDataWithRootObject:coordinateData];//archived to disk

[/code]
and then used in mapViewDidUpdateUserLocation method

[code]NSArray *coordinateData;
coordinateData= [NSKeyedUnarchiver unarchiveObjectWithData:[userDefault objectForKey:CenterCoordinatePrefKey]];//This returns @[latitude, longitude]

NSLog(@"center coordinate-- %@",coordinateData);

CLLocationCoordinate2D defaultCenter= {[[coordinateData objectAtIndex:0] doubleValue],
    [[coordinateData objectAtIndex:1] doubleValue]};

MKCoordinateSpan span= MKCoordinateSpanMake(250, 250);//Structure members
MKCoordinateRegion mapPortionToDisplay= MKCoordinateRegionMakeWithDistance(defaultCenter, span.latitudeDelta, span.longitudeDelta);
//span.latitudeDelta=250 and span.longitudeDelta=250

[worldView setRegion:mapPortionToDisplay animated:YES];[/code]

[code]#import “BNRMapPoint.h”

@implementation BNRMapPoint
@synthesize coordinate=_coordinate;
@synthesize title=_title;
@synthesize subtitle=_subtitle;

-(void)encodeWithCoder:(NSCoder *)aCoder{
NSLog(@"%@",NSStringFromSelector(_cmd));
latitude = self.coordinate.latitude;
longitude = self.coordinate.longitude;

[aCoder encodeDouble: latitude forKey:@"latitude"];
[aCoder encodeDouble:longitude forKey:@"longitude"];

}
-(id)initWithCoder:(NSCoder *)aDecoder{
NSLog(@"%@",NSStringFromSelector(_cmd));
if (self= [super init]) {
latitude= [aDecoder decodeDoubleForKey:@“latitude”];
longitude= [aDecoder decodeDoubleForKey:@“longitude”];

    self.coordinate= CLLocationCoordinate2DMake(latitude, longitude);
}
return self;

}
[/code]
The challenge asks you to do this, without using NSUserDefaults and key-value pair… This just doesn’t seem right… We are allowed to use only NSKeyedArchiver and NSKeyedUnarchiver to set and retrieve the defaults respectively… I cannot figure out how to do this without using a key-value pair. This just is confusing me… :confused: Pls help…