1

I've got a UImage, that needs to rotate until my call to the server ends. But my image rotates only one time and stops after that.

My code:

    @IBOutlet var imgLoader: UIImageView!
    override func viewDidLoad() {
    super.viewDidLoad()
    DispatchQueue.global(qos: .userInitiated).async {
        self.getSalons()
    }
    self.launchLoaderDesign()
    NotificationCenter.default.addObserver(forName:NSNotification.Name("LoadAllShowNotification"), object: nil, queue: nil, using: notificationFinish)
}

func getSalons() -> Void {
    let api:ApiSvain = ApiSvain()
    api.getHeartStrokeSalon()
    api.getSalonForHomePage()
}

func launchLoaderDesign() -> Void {
    var posImg:Int = 0
    UIView.animate(withDuration: 0.5, delay: 0, options: .curveEaseIn, animations: { () -> Void in
            self.imgLoader.transform = self.imgLoader.transform.rotated(by: CGFloat(M_PI_2))
    })
    { (finished) -> Void in
        self.launchLoaderDesign()
    }
}
func getSalonForHomePage(){
    let url = "MY_URL"
    Alamofire.request(url, method: .get).validate().responseJSON
    { response in
        if (response.error == nil)
        {
            let json = JSON(response.result.value!)

            for (index, element) in json
            {
                let show:Show = Show(json: element, index: index)
                StaticData.arrayOfShow.append(show)
            }
            NotificationCenter.default.post(name:NSNotification.Name("LoadAllShowNotification"), object: nil, userInfo: nil)
        }
        else
        {
            print(response.error!)
        }
    }
}

My function getSalonForHomePage sends a notification, and when I catch it I use performSegue to move to my new page.

I think my problem came from my misunderstanding of multi-threading.

Ps: I am using alamofire 4, for send request to my server.

DoesData
  • 6,594
  • 3
  • 39
  • 62
Badr Filali
  • 279
  • 5
  • 21

0 Answers0