Swift - UIImageview URL slideshow

3.1k Views Asked by At

Hello everyone I have a problem I can not solve , I have an application written in Object C and I wanted to make it or rewrite it or compatible with Swift . Being novice with Swift would like to know how I can set this piece of code written in Object C to swift.
Thank you for all the support that you would know me

First Slideshow Banner

//use your URL
NSData *picOne = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"URL"]];
NSData *picTwo = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"URL"]];
NSData *picThree = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"URL"]];
NSData *picFour = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"URL"]];
NSData *picFive = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"URL"]];
NSData *picSix = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"URL"]];

//then convert data to actual pictures
UIImage *onePic = [UIImage imageWithData:picOne];
UIImage *twoPic = [UIImage imageWithData:picTwo];
UIImage *threePic = [UIImage imageWithData:picThree];
UIImage *fourPic = [UIImage imageWithData:picFour];
UIImage *fivePic = [UIImage imageWithData:picFive];
UIImage *sixPic = [UIImage imageWithData:picSix];

//then SHABAM!
immagine.animationImages = [NSArray arrayWithObjects: onePic,twoPic,threePic,fourPic,fivePic,sixPic, nil];
immagine.animationDuration = 60.00f;
immagine.animationRepeatCount = 0;

[immagine startAnimating];

Second Slideshow Banner

//use second URL
NSData *picNine = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"URL"]];
NSData *picTen = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"URL"]];
NSData *picEleven = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"URL"]];

//second convert data to actual pictures
UIImage *ninePic = [UIImage imageWithData:picNine];
UIImage *tenPic = [UIImage imageWithData:picTen];
UIImage *elevenPic = [UIImage imageWithData:picEleven];

//result
immagine2.animationImages = [NSArray arrayWithObjects: ninePic,tenPic,elevenPic, nil];
immagine2.animationDuration= 50.00f;
immagine2.animationRepeatCount = 0;

[immagine2 startAnimating];
1

There are 1 best solutions below

3
On BEST ANSWER

What you are doing should look something like this in Swift.

let url = NSURL(string: image.url)
let data = NSData(contentsOfURL: url!)
imageURL.image = UIImage(data: data!)

var imgListArray :[String] = ["imageURL1", "imageURL2"...]

self.imageView.animationImages = imgListArray;
self.imageView.animationDuration = 60.0
self.imageView.repeatCount = 0
self.imageView.startAnimating()