2014-07-18 22 views
5

Po prostu chcę uzyskać zasób obrazu z ALAsset w ios 8 z Swift.IOS Swift assetForURL error

Używam SNImagePicker do wielokrotnego pobierania zdjęć.

Z objective-c używam to:

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) {  }]; 

ze SWIFT, mam próbować to zrobić:

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) 
      } 
     ) 
    } 
} 

Z tego fragmentu, i uzyskać błąd:

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

+0

Która linia jest przyczyną błędu? – RaffAl

Odpowiedz

3

Spróbuj wymienić NSLog ("Błąd!", Zero) na NSLog ("Błąd!"). Ta instrukcja powoduje, że Swift rzuca nieoczekiwane komunikaty o błędach.

enter image description here

enter image description here