Getting view of NSViewController if it is a custom class?

I use the following code to output my view from my controller:

CollectionItemView *myView = [self view]; 

This works very well, but I get a warning Incompatible pointer types initializing CollectionItemView __strong with an expression of type NSView. I understand why I understand this, but is it okay to ignore it or should I rewrite the view property?

Cartridge

+5
source share
2 answers

If you are sure there [self view]are CollectionItemView, just do:

CollectionItemView *myView = (CollectionItemView*)[self view];

or (which is better) you can use:

id myView = [self view];
+2
source

No need to rewrite it. troolee has already proposed two working solutions. However, to be saved, I would have better formulated it differently.

CollectionItemView *myView = nil;
if ([[self view] isKindOfClass:[CollectionItemView class])
  self.view = (CollectionItemView*)[self view];

isKindOfClass , , , CollectionItemView .

0

All Articles