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 nsmutablearrays 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), object nsmutablearray<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

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -