gpt4 book ai didi

IOS Swift assetForURL 错误

转载 作者:搜寻专家 更新时间:2023-10-31 08:03:34 24 4
gpt4 key购买 nike

我只想使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com