IOS Swift assetForURL 错误

标签 ios swift ios8 alassetslibrary

我只想使用 Swift 从 ios 8 中的 ALAsset 获取图像资源。

我使用 SNImagePicker 进行多张图片选取。

对于 objective-c,我使用这个:

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

使用 swift,我尝试这样做:

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

通过这段代码,我得到了一个错误:

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

最佳答案

尝试用 NSLog("Error!") 替换 NSLog("Error!", nil)。此语句导致 Swift 抛出意外错误消息。

enter image description here

enter image description here

关于IOS Swift assetForURL 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24821101/

相关文章:

ios - 新录制视频的 MediaFile.getFormatData() 包含错误信息

ios - 提交后配置文件无效

ios - 解包读取 JSON 的可选值时意外发现 nil

iPhone 上的 iOS 8 多个 <select> 严重错误?

c# - 如何使用 Xamarin 在 iOS 8 中制作表格单元格和分隔符全宽?

ios - 使用未调用的 Apple ASAuthorizationControllerDelegate 方法登录

ios - 缩小 UIImage 但返回更大的内存大小?

ios - swift + 核心数据 : Cannot Automatically Set Optional Attribute On Generated NSManagedObject Subclass

ios - tableview 上的滚动 Action

ios - x86_64 的 undefined symbol - iOS - 64 位转换 - Xcode6