Need to archive CLLocation data

前端 未结 4 678
迷失自我
迷失自我 2021-01-12 21:37

I have an array of CLLocation data that I would like to archive. Should the NSUserDefaults system be used? Otherwise, how best to archive the

4条回答
  •  广开言路
    2021-01-12 21:58

    Found out the solution using nsarchiver as you said it worked like charm thanks. Here is what i did.

    - (id)initWithCoder:(NSCoder *)aDecoder
    {
    
        self.PlaceName=[aDecoder decodeObjectForKey:@"inapPlaceName"];
    
        float lat, long1;
    
        lat=[aDecoder decodeDoubleForKey:@"inapCoordinateLat"];
    
        long1=[aDecoder decodeDoubleForKey:@"inapCoordinateLong"];  
    
        //inapCoordinate=[[CLLocationCoordinate2D alloc] initWithLatitude:lat1 longitude:long1];
        CLLocationCoordinate2D new_coordinate = { lat, long1 };
        self.inapCoordinate=new_coordinate;
    
        return self;
    
    }
    
    - (void)encodeWithCoder:(NSCoder *)aCoder
    {
    
        [aCoder encodeObject:PlaceName forKey:@"inapPlaceName"];
    
        [aCoder encodeDouble:inapCoordinate.latitude forKey:@"inapCoordinateLat"];
    
        [aCoder encodeDouble:inapCoordinate.longitude forKey:@"inapCoordinateLong"]; 
    
    }
    

提交回复
热议问题