Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread Display Modes
Old Jun 30, 2008, 09:10 AM   #1
macrumors member
Join Date: May 2007
Location: Lithuania
Document Based

Hi, I can't figure out this.
I have MyDocument class which inherits from NSDocument and DocView which intherits from NSView. DocView has IBOutlet to MyDocument. When I working inside DocView and I want to get some information from my MyDocument object, I get "null".

#import <Cocoa/Cocoa.h>
@class MyDocument;

@interface DocView : NSView {
IBOutlet MyDocument *doc;
#import <Cocoa/Cocoa.h>

@interface MyDocument : NSDocument
- (BOOL)rand;
And let's say code in DocView will be like this:
- (id)initWithFrameNSRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.

NSLog(@"Rand: %@", [doc rand]);
So I launch my application, press File, Open, I will choose my last saved file, MyDocument becomes initialized and it's time to initialize docView and it should write "Rand: YES" into the Log (rand always gives YES in this example), but I get "Rand: (null)". So why can't I contact my MyDocument?

In Interfeice Builder there is connection from CustomView (DocView) to File's Ower (MyDocument).
davidlt is offline   0 Reply With Quote
Old Jun 30, 2008, 09:40 AM   #2
macrumors regular
Join Date: Apr 2004
Location: Israel
I believe the nib loader first fully initializes all custom view objects archived in a nib before setting their outlets and other instance variables.

This would mean that your custom view doesn't yet have its outlet to MyDocument set inside its initializer. Which is where you are trying to use it, thus resulting in NULL.

Note, this should only be happening with custom views. Other objects are already initialized before ever being archived into the nib.

I may be wrong though.

Last edited by yoavcs; Jun 30, 2008 at 09:56 AM.
yoavcs is offline   0 Reply With Quote
Old Jun 30, 2008, 10:45 AM   #3
Thread Starter
macrumors member
Join Date: May 2007
Location: Lithuania
I am going to check that a bit later and write if it's true. This should mentioned somewhere in documentation, I will try to find it.

Found that:

So it works as you said. Thanks.

Last edited by davidlt; Jun 30, 2008 at 11:20 AM.
davidlt is offline   0 Reply With Quote

MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Cocoa Document Based Application Tutorial Blakeasd Mac Programming 2 Aug 2, 2011 05:08 PM
Creating a Cocoa Document Based Web Browser and Need Help Checking for "http://" macman7002 Mac Programming 10 Oct 23, 2010 09:52 PM
Edit Window in Document Based Application Blakeasd Mac Programming 1 Sep 10, 2010 06:40 PM
Any way to make the dock document based? aditghai Mac Basics and Help 2 Feb 26, 2008 06:34 AM
Adding saving to a Document based app zedLondon Mac Programming 3 Jun 25, 2007 02:21 PM

All times are GMT -5. The time now is 07:51 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013,, LLC