2016-09-21 6 views
0

Ich habe diesen merkwürdigen Fehler und habe keine Idee, es zu reparieren.Fehler Swift 3 Downcast von 'PHAsset?' zu "PHAsset" entpackt nur optionals; Wolltest du '!'

Mein Code funktionierte gut in Xcode 7.3. Aber nach dem Update auf Xcode 8 habe ich fast 17 Fehler und 21 Warnungen bekommen. Dies könnte eine Syntaxänderung in Swift sein. 3

All das gelöst, aber ich kann das nicht herausfinden: Downcast von 'PHAsset?' zu "PHAsset" entpackt nur optionals; Wolltest du '!'

Hilfe bitte

let valorFoto = tuplesFoto.valorfoto.substring(to: tuplesFoto.valorfoto.characters.index(tuplesFoto.valorfoto.endIndex, offsetBy: -4)) 

      if let asset = PHAsset.fetchAssets(withLocalIdentifiers: [valorFoto], options: nil).firstObject as? PHAsset 
      { 
       PHImageManager.default().requestImageData(for: asset, options: nil, resultHandler: { (data: Data?, identificador: String?, orientaciomImage: UIImageOrientation, info: [AnyHashable: Any]?) -> Void in 

        if let data = data 
        { 
         if let image = UIImage(data: data) 
         { 
          DispatchQueue.main.async(execute: {() -> Void in 
           self.images.updateValue(image, forKey: tuplesFoto.valorfoto) 
           self.colDragAndDrop.reloadData() 
          }) 
         } 
        } 
       }) 

      } 
      else 
      { 
       if let image = UIImage(named: "no_media") 
       { 
        images.updateValue(image, forKey: tuplesFoto.valorfoto) 
       } 
      } 
+0

Klingt wie 'fetchAssets' gibt ein' 'PHAsset?. Haben Sie versucht, nur das 'as? PHAsset? – zneak

+0

hat es funktioniert. Ich bediente Ihre Antwort vielen Dank – david

Antwort

1

Die Codezeile: vor

if let asset = PHAsset.fetchAssets(withLocalIdentifiers: [valorFoto], options: nil).firstObject as? PHAsset 

nach

if let asset = PHAsset.fetchAssets(withLocalIdentifiers: [valorFoto], options: nil).firstObject 
+0

so der Code nach funktioniert? –

Verwandte Themen