Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS Swift assetForURL error

i just want to get an image asset from the ALAsset in ios 8 with Swift.

i use the SNImagePicker for multiple images picking.

With objective-c i use this:

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

With swift, i have try to do this:

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

With this snippet, i obtain an error:

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

like image 280
Mk3d Avatar asked Oct 21 '22 05:10

Mk3d


1 Answers

Try replacing NSLog("Error!", nil) with NSLog("Error!"). This statement is causing Swift to throw unexpected error messages.

enter image description here

enter image description here

like image 124
Carl Ambroselli Avatar answered Oct 23 '22 04:10

Carl Ambroselli