objective c - How to use protocols with categories for NSMutableArray -
i don't think i've found example quite own on site though i'm sure pops time, , finished chapter on subject in my book.
i'm not looking complicated, want add functionality nsmutablearray
objects of type because don't want subclass nsmutablearray
because seems difficult, may change mind that.
i want category offers nsmutablearray
s conform ndvector
protocol ability things calculate norm, rotate axis, etc.
i've tried couple things, , i'm thinking should this:
- make protocol:
@protocol ndvector <nsmutablearray>
, declare methods there - create category
@interface nsmutablearray (ndvector)
that... declares methods? - implement methods in category's implementation
@implementation nsmutablearray (ndvector)
- and finally, somehow instantiate
nsmutablearray<ndvector>
(i'm coming java), objectnsmutablearray<ndvector> vec = [[nsmutablearray alloc] init]
how should doing this? please don't send link, provide explanation parallels methodology, correct steps involved.
none of current approaches best way. suggest create vector class happens use mutable array in own implementation.
you have init
method in vector class takes array.
Comments
Post a Comment