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'
Try replacing NSLog("Error!", nil) with NSLog("Error!"). This statement is causing Swift to throw unexpected error messages.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With