title: iOS: PHAsset & Detecting DNG RAW Format
body: <p>I got Apple's sample code for '<strong><em>SamplePhotosApp</em></strong>' and in the photo album grid photo layout, trying to detect DNG RAW files (put up a badge if it's DNG).  </p>
  
  <p>Default <strong>cellForItemAt</strong>:</p>
  
  <pre><code>override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
          let asset = fetchResult.object(at: indexPath.item)
  
          // Dequeue a GridViewCell.
          guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: GridViewCell.self), for: indexPath) as? GridViewCell
              else { fatalError("unexpected cell in collection view") }
  
          // Add a badge to the cell if the PHAsset represents a Live Photo.
          if asset.mediaSubtypes.contains(.photoLive) {
              cell.livePhotoBadgeImage = PHLivePhotoView.livePhotoBadgeImage(options: .overContent)
          }
  
          // Request an image for the asset from the PHCachingImageManager.
          cell.representedAssetIdentifier = asset.localIdentifier
          imageManager.requestImage(for: asset, targetSize: thumbnailSize, contentMode: .aspectFill, options: nil, resultHandler: { image, _ in
              // The cell may have been recycled by the time this handler gets called;
              // set the cell's thumbnail image only if it's still showing the same asset.
              if cell.representedAssetIdentifier == asset.localIdentifier {
                  cell.thumbnailImage = image
              }
          })
  
          return cell
  
      }
  </code></pre>
  
  <hr>
  
  <h2>DNG/RAW Format</h2>
  
  <p>With DNG files, there could be a preview or thumbnail (with iOS11) embedded in it, and of course a completely separate JPEG attached to it.  </p>
  
  <p>With above code, <strong>requestImage</strong> still displays DNG files by pulling out its embedded JPEG.  However, it doesn't know that the <strong>PHAsset</strong> is actually a DNG file.</p>
  
  <p><strong>How can I find out if the PHAsset is a DNG?</strong></p>
  
  <hr>
  
  <h2>Things I Tried</h2>
  
  <pre><code>let fileExtension = ((asset.value(forKey: "uniformTypeIdentifier") as! NSString).pathExtension as NSString).uppercased
  if fileExtension == "DNG" || fileExtension == "RAW-IMAGE" {
       //Show RAW Badge
  }
  </code></pre>
  
  <p>Above works only if the DNG file has just the preview JPEG embedded.  If it has a regular full-size JPEG embedded, it recognize the PHAsset as a JPEG.</p>
  
  <p>I've been told to try this:</p>
  
  <pre><code>let res = PHAssetResource.assetResources(for: asset)
  </code></pre>
  
  <p>But a certain asset could have several number of resources (adjustment data, etc).  How would I be able to make this work?</p>