objective c - May I implement one function of protocol in subclass? -


i modified it. problem if want have subclass inherit baseparticipant, may re-implement func performevent inside subclass? example:

class cyclingparticipant: baseparticipant, participant { init(name: string) {     super.init(name: name, preferredevent: event.cycling)  }  func performevent(event: event, distance: distance) throws {  }  } 

but compiler said "redundant conformance of cyclingparticipant protocol participant .

class baseparticipant: participant {  var name: string  var preferredevent: event  var racetime: int  var couldnotfinish: bool  //var performedevent: event // in swift, class accepts protocol must impletment funcs inside protocol  init(name: string, preferredevent: event) {     self.name = name     self.preferredevent = preferredevent     self.racetime = 0     self.couldnotfinish = false }  func getname() -> string {     return self.name }  func getpreferredevent() -> event {     return self.preferredevent }  func isdisqualified() -> bool {     return self.couldnotfinish }  func addtime(addtionalracetime:int) -> void {     self.racetime += addtionalracetime }  func setcouldnotfinish() -> void {     self.couldnotfinish = true } func performevent(event: event, distance: distance) throws -> int {     return 1 } func gettime() throws {  }  } 

the code of protocol participant:

protocol participant { func getname() -> string func getpreferredevent() -> event func isdisqualified() -> bool func performevent(event: event,distance: distance) throws ->int func addtime(addtionalracetime: int) func setcouldnotfinish() func gettime() throws  } 

you're missing implementation of gettime() function listed in protocol. also, should post such questions on piazza. :p

[updating answer reworded question]

the baseparticipant class adopts participant protocol, cyclingparticipant subclass should not declare adopts also, causing redundant conformance error. because baseparticipant participant, subclass of baseparticipant participant.

change:

class cyclingparticipant: baseparticipant, participant 

to:

class cyclingparticipant: baseparticipant 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -