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: http://developer.apple.com/documenta...inkElementID_7

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

Similar Threads
thread Thread Starter Forum Replies Last Post
basic core data saving in a document-based app Yashman! Mac Programming 0 Apr 10, 2014 07:58 AM
Document based application, use folders (of any type) as documents printz Mac Programming 0 Oct 30, 2013 01:02 PM
How do I automatically create and populate folders based on document names auslegung Mac Basics and Help 4 Feb 17, 2013 06:14 PM
Threading of Core Data in a document based application bitdoctor Mac Programming 0 Sep 25, 2012 01:30 AM
Package-based document trouble Starfox Mac Programming 1 Jun 7, 2012 02:59 AM

Forum Jump

All times are GMT -5. The time now is 12:24 PM.

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

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2015, MacRumors.com, LLC