ios - How to conform to an objective c protocol in an existing .h file in Swift? -
i trying recreate ray wenderlich tutorial in swift, using both swift , objective c. main part (i.e. view controllers , models) done in swift , using bridging header existing .h , .m classes.
i having trouble trying swift view controller conform obj-c delegate.
in .h file have:
@class rwtrateview; @protocol rwtrateviewdelegate - (void)rateview:(rwtrateview *)rateview ratingdidchange:(float)rating; @end @interface rwtrateview : uiview ... @property (assign) id <rwtrateviewdelegate> delegate; @end
in swift file have:
class detailviewcontroller: uiviewcontroller, uitextfielddelegate, rwtrateviewdelegate, uiimagepickercontrollerdelegate, uinavigationcontrollerdelegate { @iboutlet var rateview : rwtrateview ... func configureview() { // update user interface 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 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 reason, i'm getting error message saying type 'detailviewcontroller" not conform protocol 'rwtrateviewdelegate' , i'm not quite sure why.
the full code @ https://github.com/dwmchan/scarybugsswift.
would appreciate feedback on because i've spent last 3 days looking answers online couldn't find on this.
you have:
func rateview(rateview:rwtrateview!, ratingdidchange rating:float!) ->void {
my xcode 6 (beta 2) autocompletes line
func rateview(rateview: rwtrateview!, ratingdidchange rating: cfloat) {
note second parameter's type cfloat
, not float!
.
Comments
Post a Comment