Tocropviewcontroller: Swift 3 Support

Created on 4 Oct 2016  ·  6Comments  ·  Source: TimOliver/TOCropViewController

How can I use this library with Swift 3?

enhancement question

Most helpful comment

This project is written in Objective-C and there is no need to make changes in code (or rewrite it completely in Swift) to use it in Swift 3 or other Swift version code, because Objective-C and Swift files can coexist in a single project. So if you use it via CocoaPods then 'Basic Implementation' example from Readme in Swift will look like:

import TOCropViewController

func presentCropViewController() {
    let image: UIImage = ... // Load an image
    let cropViewController = TOCropViewController(image: image)
    cropViewController.delegate = self
    present(cropViewController, animated: true, completion: nil)
}

func cropViewController(_ cropViewController: TOCropViewController!, didCropTo image: UIImage!, with cropRect: CGRect, angle: Int) {
    // 'image' is the newly cropped version of the original image
}

If you copy source to Swift project than check out 'Importing Objective-C into Swift' section here https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html and then use like example above.

All 6 comments

It should just work if you drop it in add an Objective-C bridging header! :)

At some point, I'l see if I can improve the API design to make it more 'Swifty' as well.

I'm using TOCropViewController in Swift 3 project via cocoapods, working good no errors.

We expect swift version please # @akovalov :) :) :)

@osmanyildirim It's really not possible to 'expect' anything of a free open source project. ;)

If you desperately require native Swift 3 support, feel free to implement it yourself. :D

This project is written in Objective-C and there is no need to make changes in code (or rewrite it completely in Swift) to use it in Swift 3 or other Swift version code, because Objective-C and Swift files can coexist in a single project. So if you use it via CocoaPods then 'Basic Implementation' example from Readme in Swift will look like:

import TOCropViewController

func presentCropViewController() {
    let image: UIImage = ... // Load an image
    let cropViewController = TOCropViewController(image: image)
    cropViewController.delegate = self
    present(cropViewController, animated: true, completion: nil)
}

func cropViewController(_ cropViewController: TOCropViewController!, didCropTo image: UIImage!, with cropRect: CGRect, angle: Int) {
    // 'image' is the newly cropped version of the original image
}

If you copy source to Swift project than check out 'Importing Objective-C into Swift' section here https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html and then use like example above.

I had a bit of a play with adding better Swift interoperability with this project. Short of doing a complete refactor of the method names using NS_SWIFT_NAME, I THINK that's about as much as we can do.

If you can think of anything else it needs to make Swift interop better, please file a PR. :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

asadqazi picture asadqazi  ·  3Comments

ntnmrndn picture ntnmrndn  ·  4Comments

yarodevuci picture yarodevuci  ·  8Comments

trr-amsiq picture trr-amsiq  ·  10Comments

mugunth87 picture mugunth87  ·  5Comments