• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Trouble with design pattern
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Trouble with design pattern


  • Subject: Trouble with design pattern
  • From: Carlos Eduardo Mello <email@hidden>
  • Date: Fri, 18 Feb 2011 17:20:47 -0200

Hi Everyone,

I am comming back to cocoa programming and to this list after a few years without programming anything, so please forgive me in advance for any stupid questions. I've read the docs, studied Hillegass's book again and searched the archives, but still couldn't find a definitive answer to my questions.

My app is document-based, started from the XCode template. I have two custom views which are outlets of MyDocument and some extra buttons and text fields on the document's NIB file. Drawing, actions and events work fine for the most part. but in order to do the fun stuff with the app, I need to acess methods in the document as a result of mouse events in the custom views, like updating the values in the text fields and making modifications to my data model classes (the data engine is a collection of crossplatform C++ classes). I came across a few suggestions in cocoa-dev's archives from a few years ago, but they didn't seem quite it.

1. Create outlets in the view's subclasses and point them to MyDocument using IB;
2. Create outlets as in 1., but adding acessor methods to initialize them;
3. accessing MyDocument with messages to the class hierarchy , as in [[[self window] windowController] document];


I tried to use a mix of these approaches, or in other words: query the window controller for the document and then store its reference inside the views forq quicker access. Here's where I get stuck:

In order to use 1. or 2., I need to declare an instance of MyDocument inside my view's classes. The compiler won't let me do this unless I import MyDocument to the class definitions. The problem is that the classes are already included in MyDocument and the "chicken/egg" thing makes XCode spit a zillion compile errors (naturally). I tried declaring the variables inside the custom views as type 'id' and tested the approach calling a MyDocument method which shows some data in various textfields. The code compiled and ran, but MyDocument never got the messages.

// inside custom view's class definition
id document;

// inside awakeFromNib
document = [ [ [ self window ] windowController ] document ];

// inside mouseUp
[document refreshParameters];

If I just query the window controler for the document on demand like this:

[ [ [ [ self window ] windowController ] document refreshParameters ];

the code works, but I still can't get rid of those "message-not-found" warnings:

"warning: no '-refreshParamters' method found
(Messages without a matching method signature will be assumed to return 'id' and accept '...' as arguments.)"


So my questions are:

1) Is there a better way to approach this?
2) Is it OK to just call the document like this and ignore the compiler warning?


I'd really appreciate if someone could comment on this - i'd hate to find out later that i'd been building on a bad design...
Thanks already for a y help.


Carlos.


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Trouble with design pattern
      • From: Jon Gary <email@hidden>
    • Re: Trouble with design pattern
      • From: aglee <email@hidden>
    • Re: Trouble with design pattern
      • From: email@hidden
  • Prev by Date: Re: Avoiding NSTableView NSOutlineView menu row highlight
  • Next by Date: Re: Trouble with design pattern
  • Previous by thread: Re: Avoiding NSTableView NSOutlineView menu row highlight
  • Next by thread: Re: Trouble with design pattern
  • Index(es):
    • Date
    • Thread