title: NSDictionary file emailed different than same file in app
body: <p>In my app, I store about 6 different keys in an NSDictionary and store that dictionary as a file so that it can be sent to other users of the app. Three of my keys are numbers that I store as strings: (for example)</p>
  
  <pre><code> NSString *altitudeData = [NSString stringWithFormat:%1.50f",_altitude];
   [mutableDict setObject:altitudeData forKey:@"altitude"];
   [mutableDict writeToFile:filePath atomically:YES];
  </code></pre>
  
  <p>I zip it up with some relevant media files and send it.</p>
  
  <p>Usually everything works fine. The app receives the zipped file, unzips it, reads the NSDictionary file (which is basically an XML) and creates an object based off of the information it just received.</p>
  
  <p>However things do not work right consistently. This problem has me particularly baffled because I had the same exact file sent to my app and to my computer. The keys that were numbers I had stored as strings (like my example above) are changed to 0.00000……… in the file my app reads.</p>
  
  <pre><code> &lt;key&gt;altitude&lt;/key&gt;
   &lt;string&gt;0.00000000000000000000000000000000000000000000000000&lt;/string&gt;
  </code></pre>
  
  <p>I open the NSDictionary as an XML on my computer though and I can clearly see that they are correct and as they were when I exported them.</p>
  
  <pre><code> &lt;key&gt;altitude&lt;/key&gt;
   &lt;string&gt;27.19356918334960937500000000000000000000000000000000&lt;/string&gt;
  </code></pre>
  
  <p>I have confirmed several times that these are indeed the same file, and everything else is the same. I've also tried erasing my app and re-running to make sure I wasn't accidentally reading the wrong file. How and why are these fields transformed? Is there anything I can do to prevent it?</p>
  
  <p><strong>edit:In response to a request about how I'm zipping the file</strong>
  I'm actually using some code I imported from github for that purpose</p>
  
  <pre><code>     //first locate temp directory
       NSString *tmpDirectory = NSTemporaryDirectory();
       NSMutableString *fileNameOfZip = [NSMutableString stringWithFormat:@"%@.zip",_name];
       [fileNameOfZip replaceOccurrencesOfString:@" " withString:@"_" options:NSBackwardsSearch range:NSMakeRange(0, fileNameOfZip.length)];
       NSString *zipFilePath = [tmpDirectory stringByAppendingPathComponent:
                                fileNameOfZip];
  
       //then find all files related to zipping
       NSString *mainFilePath = [FILE_DIR stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.xml",_name]];
       NSString *imageFilePath = [self saveImages];
       NSString *videoFilePath = [self saveVideo];
       NSString *audioFilePath = [self saveAudio];
       NSMutableArray *filesToAdd = [[NSMutableArray alloc]initWithObjects: nil];
       [filesToAdd addObject:mainFilePath];
       [filesToAdd addObject:imageFilePath];
       [filesToAdd addObject:videoFilePath];
       [filesToAdd addObject:audioFilePath];
       ////HERE IS THE CLASS IMPORTED FROM github
       bool successful_zip = [SSZipArchive createZipFileAtPath:zipFilePath withFilesAtPaths:filesToAdd];
  </code></pre>
  
  <p><strong>to unzip:</strong></p>
  
  <pre><code>     NSData *fileAsData = [NSData dataWithContentsOfURL:file];
       NSString *urlAsString = file.absoluteString;
       NSArray *brokenFile = [urlAsString componentsSeparatedByString:@"/"];
       NSString *fileName = [brokenFile lastObject];
       NSString *buildPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"constructing"];
       createDirectory(buildPath);
       NSString *filePath = [buildPath stringByAppendingPathComponent:fileName];
       [fileAsData writeToFile:filePath atomically:NO];
       ////HERE IS THE CLASS IMPORTED FROM github
       bool upziped = [SSZipArchive unzipFileAtPath:filePath toDestination:buildPath];
       if (upziped) {
           NSLog(@"unzipped");
       }
       else {
           NSLog(@"not unzipped");
       }
       NSArray* buildDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:buildPath error:NULL];
  
       //import NSDictionary file
       ObjectItem *object = nil; /* This is the object I'm re-creating with my file*/
       for (NSString*s in buildDirectory) {
           NSLog(@"files here: %@",s);
           if ([s rangeOfString:@".xml"].location != NSNotFound) {
               NSString *name = [[s componentsSeparatedByString:@"."]firstObject];
               object = [ObjectItem retrieveFromName:name];
               break;
           }
       }
  
       //import image
       UIImage *image;
       for (NSString *media in buildDirectory) {
           if ([media rangeOfString:@".png"].location != NSNotFound) {
               NSString *imageFilePath = [buildPath stringByAppendingPathComponent:media];
               image = [[UIImage alloc]initWithContentsOfFile:imageFilePath];
               [object importImage:image];
               break;
           }
       }
  
       //import video
       for (NSString *media in buildDirectory) {
           if ([media rangeOfString:@".MOV"].location != NSNotFound) {
               NSString *videoFilePath = [buildPath stringByAppendingPathComponent:media];
               [object importVideo:videoFilePath];
               break;
           }
       }
  
       //import audio
       NSString *audioExt = [NSString stringWithFormat:@".%@",AUDIO_EXT];
       for (NSString *media in buildDirectory) {
           if ([media rangeOfString:audioExt].location != NSNotFound) {
               NSString *audioFilePath = [buildPath stringByAppendingPathComponent:media];
               [object importAudio:audioFilePath];
               break;
           }
       }
  
       [object save];
  </code></pre>
  
  <p><strong>Also incase it's helpful here the [ObjectItem retrieveFromName] method</strong></p>
  
  <pre><code> +(ObjectItem
        *)retrieveFromName:(NSString*)name {
       NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
       NSString *documentsDirectory = [paths objectAtIndex:0];
       NSString *subDirectory = [documentsDirectory stringByAppendingPathComponent:@"ObjectItems"];
       createDirectory(subDirectory);
       NSString *filePath = [subDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.xml",name]];
       NSString *file = [NSString stringWithContentsOfFile:filePath encoding:NSASCIIStringEncoding error:nil];
       NSLog(@"file contents:\n%@\n",file);
       file = nil;
       NSDictionary *myDict = [NSDictionary dictionaryWithContentsOfFile:filePath];
       for (NSString *s in myDict) {
           NSLog(@"key \"%@\" has value: %@",s,[myDict objectForKey:s]);
       }
       double lat = [[myDict objectForKey:@"latitude"]doubleValue];
       double lon = [[myDict objectForKey:@"longitude"]doubleValue];
       double alt = [[myDict objectForKey:@"altitude"]doubleValue];
       CLLocation *loc = [[CLLocation alloc]initWithCoordinate:CLLocationCoordinate2DMake(lat, lon)
                                                      altitude:alt
                                            horizontalAccuracy:kCLLocationAccuracyBestForNavigation
                                              verticalAccuracy:kCLLocationAccuracyBestForNavigation
                                                     timestamp:[NSDate date]];
       UIImage *im = nil;
       NSString *vid = nil;
       NSString *aud = nil;
  
       ObjectItem
         *object
         = [[ObjectItem
         alloc]initWithName:name location:loc];
       NSString *key = [myDict objectForKey:@"image"];
       if (key != nil) {
           im = [UIImage imageWithContentsOfFile:key];
           [object
         importImage:[im copy]];
       }
       key = nil;
       key = [myDict objectForKey:@"video"];
       if (key != nil) {
           vid = [NSString stringWithString:key];
           [object
         importVideo:[vid copy]];
       }
       key = nil;
       key = [myDict objectForKey:@"audio"];
       if (key != nil) {
           aud = [NSString stringWithString:key];
           [object
         importAudio:[aud copy]];
       }
       paths = nil;
       documentsDirectory = subDirectory = filePath = nil;
       im = nil;
       vid = nil;
       aud = nil;
       myDict = nil;
       key = nil;
       return object
        ;
   }
  </code></pre>