5

I use the following code to get my View out of my controller:

CollectionItemView *myView = [self view]; 

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

chuck

John Topley
  • 113,588
  • 46
  • 195
  • 237
hakkurishian
  • 266
  • 1
  • 3
  • 13

2 Answers2

2

If you are sure that [self view] is CollectionItemView just do:

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

or (which is better) you can use:

id myView = [self view];
Pavel Reznikov
  • 2,968
  • 1
  • 18
  • 17
0

There is no need to overwrite it. troolee already suggested two working solutions. However, just to be save I'd rather code it differently.

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

The shorter version without isKindOfClass test is ok when you know for sure from the context that the object must be of type CollectionItemView or any of its subclasses.

Hermann Klecker
  • 14,039
  • 5
  • 48
  • 71