okmr-d / DOFavoriteButton

Cute Animated Button written in Swift.
MIT License
3.61k stars 297 forks source link

swift 2.2 Does not work with latest xcode/swift update - selectors is deprecated #23

Open kiwo12345 opened 8 years ago

kiwo12345 commented 8 years ago

I get a few warnings saying that the selectors need to change form: self.addTarget(self, action: "touchDown:", forControlEvents: UIControlEvents.TouchDown) self.addTarget(self, action: "touchUpInside:", forControlEvents: UIControlEvents.TouchUpInside) self.addTarget(self, action: "touchDragExit:", forControlEvents: UIControlEvents.TouchDragExit) self.addTarget(self, action: "touchDragEnter:", forControlEvents: UIControlEvents.TouchDragEnter) self.addTarget(self, action: "touchCancel:", forControlEvents: UIControlEvents.TouchCancel) to:

self.addTarget(self, action: #selector(DOFavoriteButton.touchDown(:)), forControlEvents: UIControlEvents.TouchDown) self.addTarget(self, action: #selector(DOFavoriteButton.touchUpInside(:)), forControlEvents: UIControlEvents.TouchUpInside) self.addTarget(self, action: #selector(DOFavoriteButton.touchDragExit(:)), forControlEvents: UIControlEvents.TouchDragExit) self.addTarget(self, action: #selector(DOFavoriteButton.touchDragEnter(:)), forControlEvents: UIControlEvents.TouchDragEnter) self.addTarget(self, action: #selector(DOFavoriteButton.touchCancel(_:)), forControlEvents: UIControlEvents.TouchCancel)

But updating the selectors will result in my app crashing giving me the error: libc++abi.dylib: terminating with uncaught exception of type NSException

[Test.DOFavoriteButton select:]: unrecognized selector sent to instance 0x7fea9ad6f480 2016-03-29 23:07:17.286 Test[16889:2397051] *\ Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Test.DOFavoriteButton select:]: unrecognized selector sent to instance 0x7fea9ad6f480'

kiwo12345 commented 8 years ago

Okey I got it working now.. If anyone is using Swift 2.2 change addTargets() to:

private func addTargets() {
        //===============
        // add target
        //===============
        self.addTarget(self, action: #selector(DOFavoriteButton.touchDown(_:)), forControlEvents: UIControlEvents.TouchDown)
        self.addTarget(self, action: #selector(DOFavoriteButton.touchUpInside(_:)), forControlEvents: UIControlEvents.TouchUpInside)
        self.addTarget(self, action: #selector(DOFavoriteButton.touchDragExit(_:)), forControlEvents: UIControlEvents.TouchDragExit)
        self.addTarget(self, action: #selector(DOFavoriteButton.touchDragEnter(_:)), forControlEvents: UIControlEvents.TouchDragEnter)
        self.addTarget(self, action: #selector(DOFavoriteButton.touchCancel(_:)), forControlEvents: UIControlEvents.TouchCancel)
    }

then change select() to

public func select() {
        select(animate: true)
    }
grantkemp commented 8 years ago

There is a pull request to fix this code.. will it be merged?

sinanku commented 8 years ago

Waiting on this merge to implement

jwardle commented 8 years ago

+1

angadn commented 8 years ago

Doing a Carthage build doesn't work either - most likely because of this same issue. Waiting to be able to use this framework!

galharth commented 8 years ago

@kiwo12345 I can't add animate:true to the select, and getting "[DOFavoriteButton.DOFavoriteButton select:]: unrecognized selector sent to instance "