TimOliver / TOCropViewController

A view controller for iOS that allows users to crop portions of UIImage objects
http://www.timoliver.com.au/2015/06/21/tocropviewcontroller-an-open-source-image-cropper-for-ios/
MIT License
4.67k stars 929 forks source link

Support `actor isolated` and `existential any`. #563

Closed noppefoxwolf closed 3 months ago

TimOliver commented 3 months ago

Thanks for the PR @noppefoxwolf! Admittedly I'm still new to Swift concurrency; why is this required?

It would require bumping the minimum version of this library to iOS 12, and I'm still trying to aim to support iOS 11... 😅

noppefoxwolf commented 3 months ago

I fixed platform version because deprecated. But it's not related my changes. So, I reverted code.

See also: https://developer.apple.com/documentation/packagedescription/supportedplatform/iosversion/v9

noppefoxwolf commented 3 months ago

Actor isolation is introduced by Swift5.5. https://github.com/apple/swift-evolution/blob/main/proposals/0313-actor-isolation-control.md

The actor is clarify where function called what thread. In default, Delegator doesn't know actor. So, It should call with Task method even if delegate called from main thread.

protocol Delegate {
  func onTap()
}

extension ViewController: Delegate {
  func onTap() {
    Task {
      await self.updateBackgroundColor()
    }
  }
}

If all delegate method called from main thread, protocol is prefer to have @MainActor. Delegators no longer need to write Task or self.

@MainActor protocol Delegate {
  func onTap()
}

extension ViewController: Delegate {
  func onTap() {
    updateBackgroundColor()
  }
}
TimOliver commented 3 months ago

Ahhh I see! No problems then! I'll double check it still works with iOS 11 and merge it in.

Thanks so much for that!