2014-07-18 34 views
5

Sadece Swift ile ios 8'de ALAsset'ten bir resim öğesi almak istiyorum.IOS Swift assetForURL hatası

Birden çok resim çekme için SNImagePicker'ı kullanıyorum. Amaç-c ile

ben bu kullanın: hızlı With

for (int i = 0; i < info.count; i++) { 
    ALAssetsLibrary *assetLibrary=[[ALAssetsLibrary alloc] init]; 
    [assetLibrary assetForURL:info[i] resultBlock:^(ALAsset *asset) { 
     UIImage *image = [UIImage imageWithCGImage:[asset aspectRatioThumbnail]]; 
    } failureBlock:^(NSError *error) {  }]; 

, bunu yapmak için denemek var:

Type 'CVarArg' does not conform to protocol 'NilLiteralConvertible'

: Bu pasajı ile

func imagePicker(imagePicker: SNImagePickerNC!, didFinishPickingWithMediaInfo info: NSMutableArray!){ 
    var i: Int = Int(0); 
    for (i; i < info.count as Int; i++){ 
     var url: NSURL = info[i] as NSURL 
     var assetLibrary: ALAssetsLibrary = ALAssetsLibrary() 

     // 
     //assetLibrary.assetForURL(NSURL?(), resultBlock: ALAssetsLibraryAssetForURLResultBlock?(), failureBlock: ALAssetsLibraryAccessFailureBlock?())    
     // 

     assetLibrary.assetForURL(url, resultBlock: { 
      (asset: ALAsset!) in 
      if asset != nil { 
       var assetRep: ALAssetRepresentation = asset.defaultRepresentation() 
       var iref = assetRep.fullResolutionImage().takeUnretainedValue() 
       var image = UIImage(CGImage: iref) 

       self.imageViewPreview.contentMode = UIViewContentMode.ScaleAspectFill 
       self.imageViewPreview.image = image 

      } 
      }, failureBlock: { 
       (error: NSError!) in 

       NSLog("Error!", nil) 
      } 
     ) 
    } 
} 

i bir hata elde

+0

satırlarından hangisi hataya neden oluyor? – RaffAl

cevap

3

NSLog ("Hata!") Ile NSLog ("Hata!", Nil) değiştirmeyi deneyin. Bu ifade, Swift'in beklenmedik hata iletileri vermesine neden oluyor.

enter image description here

enter image description here