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

`-[_SwiftValue bounds]: unrecognized selector sent to instance 0x170258150` Crash after Swift 3.0 Upgrade #230

Closed shakked closed 7 years ago

shakked commented 8 years ago

Once I updated my app to Swift 3.0, I started experiencing this crash. Here is the code where I set the MGSwipeButton

            let endStory = MGSwipeButton(title: "  End   ", backgroundColor: Colors.crewRedColor, callback: { (cell) -> Bool in
                self.activityIndicator.startAnimation()
                self.querier.endStory(story, completion: { (succeeded, error, story) -> (Void) in
                    self.activityIndicator.stopAnimation()
                    guard let story = story , succeeded else {
                        (error ?? .unknownError).showAlert(self)
                        return
                    }
                    inMainQueue {
                        self.viewsListItems = self.viewsListItems.filter({ $0.story != story })
                    }
                })
                Analytics.log(Events.Story_Ended)
                return true
            })

            cell.rightButtons = [endStory]
nightwill commented 8 years ago

+1

rmsutton commented 8 years ago

Seems like the problem stems from the fact that Swift 3 now treats all explicitly unwrapped optional types as Optional<T>. The following is a quick fix for the problem.

cell.rightButtons = [endStory!]

The alternative would be to modify the MGSwipeButton constructor so that it returns the Objective-C equivalent of MGSwipeButton and notMGSwipeButton?.

MortimerGoro commented 8 years ago

I'm going to improve the ObjC annotations for Swift and add a full Swift sample

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