title: Creation Date from Camera Roll Image
body: <p>I'm struggling with getting the creation date from an image selected in the camera roll.
  Here is my code:</p>
  
  <pre><code>    func imagePickerController(picker: UIImagePickerController!, didFinishPickingMediaWithInfo info:NSDictionary!) {
      var tmpImg = info[UIImagePickerControllerOriginalImage] as UIImage
      var metaData: NSDictionary
      var exifData: NSDictionary
  
      let library = ALAssetsLibrary()
      var dataJpeg:  NSData
  
      var url: NSURL = info.objectForKey(UIImagePickerControllerReferenceURL) as NSURL
  
      library.assetForURL(url, resultBlock: {
          (asset: ALAsset!) in
          if asset != nil {
              var image_representation : ALAssetRepresentation = asset.defaultRepresentation()
  
              var iref : CGImage = assetRep.fullResolutionImage().takeUnretainedValue()
  
              //How do I get DateTime from CGImage in Swift??              
          }
          }, failureBlock: {
              (error: NSError!) in
  
              NSLog("Error!")
          }
      )
  </code></pre>
  
  <p>}</p>
  
  <p>In an older Xcode Version with Objective-C I did this which works fine:</p>
  
  <pre><code>- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
  
  UIImage *chosenImage = info[UIImagePickerControllerOriginalImage];
  
  
  //////////////////////////
  
  
  ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
  [library assetForURL:[info objectForKey:UIImagePickerControllerReferenceURL]
           resultBlock:^(ALAsset *asset) {
  
               ALAssetRepresentation *image_representation = [asset defaultRepresentation];
  
               // create a buffer to hold image data
               uint8_t *buffer = (Byte*)malloc(image_representation.size);
               NSUInteger length = [image_representation getBytes:buffer fromOffset: 0.0  length:image_representation.size error:nil];
  
               if (length != 0)  {
  
                   // buffer -&gt; NSData object; free buffer afterwards
                   NSData *adata = [[NSData alloc] initWithBytesNoCopy:buffer length:image_representation.size freeWhenDone:YES];
  
                   // identify image type (jpeg, png, RAW file, ...) using UTI hint
                   NSDictionary* sourceOptionsDict = [NSDictionary dictionaryWithObjectsAndKeys:(id)[image_representation UTI] ,kCGImageSourceTypeIdentifierHint,nil];
  
                   // create CGImageSource with NSData
                   CGImageSourceRef sourceRef = CGImageSourceCreateWithData((__bridge CFDataRef) adata,  (__bridge CFDictionaryRef) sourceOptionsDict);
  
                   // get imagePropertiesDictionary
                   CFDictionaryRef imagePropertiesDictionary;
                   imagePropertiesDictionary = CGImageSourceCopyPropertiesAtIndex(sourceRef,0, NULL);
  
                   // get exif data
                   CFDictionaryRef exif = (CFDictionaryRef)CFDictionaryGetValue(imagePropertiesDictionary, kCGImagePropertyExifDictionary);
                   NSDictionary *exif_dict = (__bridge NSDictionary*)exif;
  
                   NSString *creationdate=exif_dict[@"DateTimeOriginal"];
  
  
  
                   // clean up
                   CFRelease(imagePropertiesDictionary);
                   CFRelease(sourceRef);
               }
               else {
                   NSLog(@"image_representation buffer length == 0");
               }
           }
          failureBlock:^(NSError *error) {
              NSLog(@"couldn't get asset: %@", error);
          }
   ];}
  </code></pre>
  
  <p>I'd be very grateful if someone could help me get the CreationDate out of the Image.</p>