Delegates, protocols, and optional methods


hey everybody, want make create delegate protocol 1 of classes , have quick question. i'm trying make couple of methods optional, i've not found great way rid of warning i'm getting.

here's i'm doing now

code:
  ---------------    @protocol myclassprotocol    - (void)dofoo;    @optional     - (void)barhappened    @end    ---------------    @interface myclass : nsobject {    id<myclassprotocol> delegate  }    @property (assign) id<classprotocol> delegate;    - (void)dobar;    @end    ---------------    @implementation myclass    - (void)dobar {      // bar      if ([delegate responsetoselector:@selector(barhappened)]) {      [delegate barhappened];    }  }    // other method telling delegate dofoo    ---------------    #import "myclass.h" // protocol  @interface thedelegate : nsobject <myclassprotocol> {    }    @end    ---------------    @implementation thedelegate    - (id)init {    //init myclass here , set self delegate  }    - (void)dealloc {    // release myclass  }    //delegate method myclass  - (void)dofoo {    // fooey stuff  }    //optional delegate method myclass  - (void)barhappened {    // tell something wonderful turn of events  }
the basic problem here of course warning delegate may not respond respondstoselector:, because method defined in nsobject , delegate defined id conforming myclassdelegate protocol.

there easy way let compiler know delegate respond?

guess change delegate id nsobject, seems bit of pain. seems there should easier way.

adding dummy responds selector method protocol seems bad idea.

of course ignore warning, don't want to. it's warning i'm getting:p.

feel i'm missing easy.

help!
 

belated answer

2 issues:
protocol should
@protocol myclassprotocol <nsobject>

...and warning because calling responsetoselector: not respondstoselector:

have figured out now, looking answer question, found this, found answer elsewhere, i'll post here next seeker.
 


Forums iPhone, iPad, and iPod Touch iOS Programming


  • iPhone
  • Mac OS & System Software
  • iPad
  • Apple Watch
  • Notebooks
  • iTunes
  • Apple ID
  • iCloud
  • Desktop Computers
  • Apple Music
  • Professional Applications
  • iPod
  • iWork
  • Apple TV
  • iLife
  • Wireless

Comments

Popular posts from this blog

need help with itunes 7.7

Rogers Listens.

Font book issue in firefox3