MGSwipeTableCell icon indicating copy to clipboard operation
MGSwipeTableCell copied to clipboard

Swift 3.0 - type conflict

Open thedc89 opened this issue 9 years ago • 11 comments

 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?

thedc89 avatar Sep 19 '16 12:09 thedc89

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

Faisal0sal avatar Sep 22 '16 08:09 Faisal0sal

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

thedc89 avatar Sep 22 '16 09:09 thedc89

@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.

felixfrtz avatar Sep 22 '16 15:09 felixfrtz

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

thedc89 avatar Sep 24 '16 09:09 thedc89

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
        }

thedc89 avatar Sep 24 '16 09:09 thedc89

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
        })]

Faisal0sal avatar Sep 24 '16 10:09 Faisal0sal

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?

jarkoAndroid avatar Sep 26 '16 14:09 jarkoAndroid

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

MortimerGoro avatar Oct 01 '16 23:10 MortimerGoro

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?

Shoshin23 avatar Oct 21 '16 12:10 Shoshin23

@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.

MortimerGoro avatar Oct 21 '16 12:10 MortimerGoro

@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

    }

Shoshin23 avatar Oct 21 '16 12:10 Shoshin23