MortimerGoro / MGSwipeTableCell

An easy to use UITableViewCell subclass that allows to display swippable buttons with a variety of transitions.
MIT License
6.96k stars 1.07k forks source link

Swift 3.0 - type conflict #233

Open thedc89 opened 8 years ago

thedc89 commented 8 years ago
 let btn:MGSwipeButton = MGSwipeButton(title: "", icon: img, backgroundColor: nil, insets: ins, callback: {
            (sender: MGSwipeTableCell!) -> Bool in

            self.pageTextField.isHidden = false
            self.pageTextField.respectiveCellNumber = (indexPath as NSIndexPath).row
            self.pageTextField.becomeFirstResponder()
            self.customControl.isHidden = true
            self.view.bringSubview(toFront: self.pageTypeView)

            return true
            })

Returns a following error:

Cannot convert value of type '(MGSwipeTableCell!) -> Bool' to expected argument type 'MGSwipeButtonCallback!'

How to edit it to make it work?

Faisal0sal commented 8 years ago

how did u fix it? I'm running through the same problem with Swift 3

thedc89 commented 8 years ago

Solution:

let buttonCallback:MGSwipeButtonCallback = {
            (sender: MGSwipeTableCell!) -> Bool in

            self.pageTextField.isHidden = false
            self.pageTextField.respectiveCellNumber = (indexPath as NSIndexPath).row
            self.pageTextField.becomeFirstResponder()
            self.customControl.isHidden = true
            self.view.bringSubview(toFront: self.pageTypeView)

            return true
        } as! MGSwipeButtonCallback

        let btn:MGSwipeButton = MGSwipeButton(title: "", icon: img, backgroundColor: nil, insets: ins, callback: buttonCallback
felixfrtz commented 8 years ago

@thedc89 Thanks for your solution. However, I am getting a Thread 1: EXC_BAD_INSTRUCTION for the as! MGSwipeButtonCallback when my TableView is loaded. Did you experience this? I hope this awesome Git gets a proper Swift 3 conversion soon.

thedc89 commented 8 years ago

Oh, I get this same error! I have to reopen the issue

thedc89 commented 8 years ago

this works for me:

let buttonCallback:MGSwipeButtonCallback = {_ in 

            self.pageTextField.isHidden = false
            self.pageTextField.respectiveCellNumber = (indexPath as NSIndexPath).row
            self.pageTextField.becomeFirstResponder()
            self.customControl.isHidden = true
            self.view.bringSubview(toFront: self.pageTypeView)

         return true
        }
Faisal0sal commented 8 years ago

Both solutions did not work for me. I'm still initiating both of the buttons inside the array like

cell.leftButtons = [MGSwipeButton(title: "Delete", backgroundColor: UIColor.red, callback: {
            (MGSwipeTableCell) -> Bool in
            self.messages.remove(at: indexPath.row)
            tableView.deleteRows(at: [indexPath], with: .fade)
            print("Delete!")
            return true
        }),MGSwipeButton(title: "More",backgroundColor: UIColor.lightGray, callback: {
            (MGSwipeTableCell) -> Bool in
            // -- More button clicked

            print("More!")
            return true
        })]
jarkoAndroid commented 8 years ago

I changed a bit syntax from "(sender: MGSwipeTableCell) -> Bool" to "_ -> Bool", now cells appear but on click the app will be crashed on AppDelegate EXC_BAD_INSTRUCTION - any more ideas?

MortimerGoro commented 8 years ago

I've pushed 1.5.6 version with Swift interoperation improvements. The swift 3.0 sample is ready too ;)

https://github.com/MortimerGoro/MGSwipeTableCell/tree/master/demo/MailAppDemoSwift

Shoshin23 commented 8 years ago

I'm facing the same issue @jarkoAndroid. I've implemented both the solutions and also studied the example by @MortimerGoro. My cells load but the moment I click on them, the app breaks.

Any thoughts on fixing this? I'm running my app on iOS 10. Anything I'm missing?

MortimerGoro commented 8 years ago

@Shoshin23 can you send me a testcase project with the issue? I couldn't reproduce this in the demos or in any of my apps. Also tried with iOS 10.0.

Shoshin23 commented 8 years ago

@MortimerGoro I'm pasting the exact code snippet below. Do tell me what i'm missing.

    let swipeToCard = MGSwipeButton(title: "", icon: DataService.resizeImage(UIImage(named: "swipeArrow")!, newWidth: 24), backgroundColor: UIColor.yellow) { (MGSwipeTableCell) -> Bool in
        let indexPath = self.tableView.indexPath(for: MGSwipeTableCell!)
        self.performSegue(withIdentifier: "oneLinerShow", sender: indexPath)
        return true

    }