0

I am creating simple document based app. So far I have implemented NSDocument subclass, which is Document and NSWindowController subclass, which is ToolbarWindowController. ToolbarWindowController controlls the toolbar, which has sliders to modify user's opened image.

Where I am having issue right now is applying filters (modifying image) on opened image: I can't figure out how to use opened image as source in ToolbarWindowController.

F.e. when I open image in Document I can set it as ViewController imageView, in makeWindowControllers:

- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError {
    image = [[NSImage alloc] initWithData:data];
    return YES;
}
- (void)makeWindowControllers {
    NSStoryboard* const storyboard = [NSStoryboard storyboardWithName:@"Main" bundle:nil];
    NSWindowController* const windowController = [storyboard instantiateControllerWithIdentifier:@"Document Window Controller"];
    [[((ViewController *)[windowController contentViewController]) imageView] setImage:image];

    [self addWindowController: windowController];
}

Can I somehow access my ToolbarWindowController properties/variables and create a NSImage property there to modify there opened image? Or can I access Document properties to achieve the same thing? Does it even work that way?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Vidux
  • 183
  • 1
  • 11

1 Answers1

4

NSWindowController has a document property. If everything is hooked up properly, that property will point at the NSDocument object that owns the NSWindowController.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
  • 2
    SO is no code writing service. What is the problem with accessing a property? – Amin Negm-Awad Nov 07 '18 at 18:40
  • I believe, I asked question with obvious answer... I can access `document` property, but I don't know how to access it's properties. I am trying to access it as usual `[self.document getProperty]` or `self.document.property` but it does not work, I am really confused with this document based app and apple documentation confuses me even more.. – Vidux Nov 07 '18 at 19:22
  • 1
    You'll need a cast to use dot syntax, like `((Document *)self.document).property`. You used a similar cast (to `ViewController *`) in the code you posted. Try logging `self.document`. Is it the correct class? – rob mayoff Nov 07 '18 at 20:34
  • It is correct class, casting worked like a charm! Thank you! – Vidux Nov 09 '18 at 09:06