2010-09-03 21 views
1

ok donc je veux faire une fonction publique qui retournera OUI si un objet existe, se conforme à un protocole et répond à un sélecteur. Je sais que le typedef de @selector est SEL, mais ce qui est le typedef pour @protocoliPhone SDK @selector -> SEL @protocol ->?

 
BOOL conforms(id object, ? prototype, SEL action) { 
    return (object != nil && 
     [object conformsToProtocol:prototype] && 
     [object respondsToSelector:action]); 
} 

Et je veux être en mesure d'appeler cette fonction comme:

 
if(conforms(delegate, @protocol(UIScrollViewDelegate), 
    @selector(touchesBegan:withEvent:))) { 
    [delegate touchesBegan:touches withEvent:event]; 
} 

Répondre

4

Vous recherchez le Protocol objet:

BOOL conforms(id object, Protocol *protocol, SEL action) { 
    return (object != nil && 
     [object conformsToProtocol:protocol] && 
     [object respondsToSelector:action]); 
} 
+1

vous plaisantez-vous c'était si simple? xD bahaha merci :) –