我只是希望通过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)
}
)
}
}
使用此代码段,我收到错误:
类型'CVarArg'不符合协议'NilLiteralConvertible'
答案 0 :(得分:3)
尝试用NSLog替换NSLog(“Error!”,nil)(“Error!”)。此语句导致Swift抛出意外的错误消息。