How do I conform to the objective c protocol in an existing .h file in Swift?

I'm trying to recreate Ray Wenderlich's tutorial in Swift, but using both Swift and Objective C. The main part (such as controllers and view models) is done in Swift and uses the bridge header for the existing .h and .m classes.

I am having trouble trying to get my quickview controller to match the obj-c delegate.

In my .h file I have:

@class RWTRateView;

@protocol RWTRateViewDelegate
- (void)rateView:(RWTRateView *)rateView ratingDidChange:(float)rating;
@end
@interface RWTRateView : UIView
...
@property (assign) id <RWTRateViewDelegate> delegate;

@end

      

In my swift file, I have:

class DetailViewController: UIViewController, UITextFieldDelegate, RWTRateViewDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

@IBOutlet var rateView : RWTRateView
...
    func configureView() {
            // Update the user interface for the detail item.
            if let detail:RWTScaryBugDoc = self.detailItem as? RWTScaryBugDoc {
                if let rv = self.rateView {
                    rv.notSelectedImage = UIImage(named: "shockedface2_empty.png")
                    rv.halfSelectedImage = UIImage(named: "shockedface2_half.png")
                    rv.fullSelectedImage = UIImage(named: "shockedface2_full.png")
                    rv.editable = true
                    rv.maxRating = 5
                    rv.delegate = self as RWTRateViewDelegate
                    rv.rating = detail.data.rating!
                    self.titleField.text = detail.data.title
                    self.imageView.image = detail.fullImage
                }
            }
        }
    ...

    func rateView(rateView:RWTRateView!, ratingDidChange rating:Float!) ->Void {

        if let detail = self.detailItem as? RWTScaryBugDoc {
            detail.data.rating = rating
        }
    }

...
}

      

For some reason, I get an error message indicating that the type "DetailViewController" does not conform to the "RWTRateViewDelegate" protocol, and I'm not entirely sure why.

The complete code is at https://github.com/dwmchan/ScaryBugsSwift .

Would be grateful for the feedback because I have spent the last 3 days looking for answers on the internet but I couldn't find anything.

+1


source to share


1 answer


You have:

func rateView(rateView:RWTRateView!, ratingDidChange rating:Float!) ->Void {

      

My Xcode 6 (beta 2) autocomplete this line as



func rateView(rateView: RWTRateView!, ratingDidChange rating: CFloat) {

      

Note that the second type is parameter CFloat

, not Float!

.

+1


source







All Articles