On Sep 6, 2016, at 23:26 , Gerriet M. Denkmann wrote:
>
> Anything to be done here? Or should I just forget about protocol extensions?
There’s nothing really wrong here, it’s just that it doesn’t work like you
think.
There is no *inheritance* of protocol default implementations, which means
t
Trying to eliminate code duplication I tried to use protocol extensions.
But I ran into a rather grave problem.
This probably is “working as documented”.
But it surely it is not working like I hoped it would.
Here is a Playground example:
protocol Number
{
func aFunction() -> Int
}
exte
On May 24, 2012, at 4:15 AM, Gerriet M. Denkmann wrote:
> How do I avoid duplicating method implementations using a protocol?
You don't, other than by using techniques like the ones I described. Protocols
are just for the convenience (and type-safety) of the _users_ of a class; they
don't real
On 24 May 2012, at 17:37, Graham Cox wrote:
> Turn it into two separate protocols instead, and adopt whichever protocols
> are needed in the concrete implementations. Or if one protocol is a superset
> of the other, a protocol can extend another.
I thought that a protocol only declares methods
Implement both A and B in the base class M, but don't declare them in its
@interface. Then MAB and MAX can both declare method A and have implementations
that just call super. Likewise for B.
Or, factor out A into a helper class, and similarly for B. Then have MAB and
MAX instantiate an A helpe
On May 24, 2012, at 4:14 AM, Gerriet M. Denkmann wrote:
> I have an abstract class M with subclasses MAB, MAX, MXB.
>
> There are several lengthy methods A which are used in MAB and MAX, and others
> methods B which are used in MAB and MXB.
>
> Methods A use a property NSUInteger index.
> Class
Implement abstract classes that implement the methods, then use the runtime to
copy the methods into the classes that should have them in +initialize.
Bob
On 24 May 2012, at 10:14, Gerriet M. Denkmann wrote:
> I have an abstract class M with subclasses MAB, MAX, MXB.
>
> There are several leng
Turn it into two separate protocols instead, and adopt whichever protocols are
needed in the concrete implementations. Or if one protocol is a superset of the
other, a protocol can extend another.
--Graham
On 24/05/2012, at 7:14 PM, Gerriet M. Denkmann wrote:
> Other, better solutions?
I have an abstract class M with subclasses MAB, MAX, MXB.
There are several lengthy methods A which are used in MAB and MAX, and others
methods B which are used in MAB and MXB.
Methods A use a property NSUInteger index.
Class MXB has no such property, is has NSIndexSet *indices instead.
Similar