Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@protocol extends @protocol

can @protocol extend @protocol ?

@protocol Prot1 : Prot2
@end

like in java:

public interface Interface1 extends Interface2 {
}
like image 682
okami Avatar asked Mar 03 '10 18:03

okami


People also ask

Can protocols be extended in Swift?

In Swift, you can even extend a protocol to provide implementations of its requirements or add additional functionality that conforming types can take advantage of. For more details, see Protocol Extensions. Extensions can add new functionality to a type, but they can't override existing functionality.

Can the protocols be extended?

You cannot “extend” a protocol because by definition a protocol doesn't have an implementation - so nothing to extend. (You could say that we “extend a protocol WITH some functionality”, but even an extended protocol is not something we can apply a function to.)

What is a protocol extension?

Protocols let you describe what methods something should have, but don't provide the code inside. Extensions let you provide the code inside your methods, but only affect one data type – you can't add the method to lots of types at the same time.

Can we extend final class Swift?

As per Swift documentation, final classes can be extended, but you can not override the already declared methods etc.


1 Answers

Yes, but with the syntax

@protocol Prot1 <Prot2, Prot3, Prot4> 
@end
like image 108
kennytm Avatar answered Sep 24 '22 02:09

kennytm