Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C type downcasting

I am trying to override

- (void)makeWindowControllers;

Here is the code for it:

NSStoryboard* const storyboard = [NSStoryboard storyboardWithName:@"Main" bundle:nil];
NSWindowController* const windowController = [storyboard instantiateControllerWithIdentifier:@"Document Window Controller"];

And then I would like to add an image to ViewController that user has selected through open... in Swift I would simply do:

(windowController.contentViewController as? ViewController)?.imageView?.image = openedImage

How I could do this downcasting in Objective-C? I really got confused since I haven't done much type converting while I was learning C. Thanks.

like image 657
Vidux Avatar asked Mar 11 '26 04:03

Vidux


1 Answers

[[((ViewController *)[windowController contentViewController]) imageView] setImage: openedImage];
like image 117
Vidux Avatar answered Mar 12 '26 17:03

Vidux



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!