• 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
Re: "remote" binding problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "remote" binding problem


  • Subject: Re: "remote" binding problem
  • From: Graham Cox <email@hidden>
  • Date: Wed, 7 Oct 2009 13:56:53 +1100


On 07/10/2009, at 1:29 PM, David Hirsch wrote:

@interface ModeQuizDoc : NSDocument
{
	QuizResults *quizResults;
}

@implementation ModeQuizDoc
- (id)init
{
   self = [super init];
   if (self) {
	quizResults = [[[QuizResults alloc] init] retain];

You don't need to retain here. It's already retained, so the additional retain will cause quizResults to leak, assuming the extra retain isn't balanced somewhere.
However, that isn't your problem (though lack of understanding of memory management in general, which this indicates, may well be).



   }
}


@interface QuizResults : NSObject { float currentScore; }

In Interface Builder, I would like to bind a text field to the current score. When I set up the text field value's binding to File's Owner.quizResults.currentScore, the app crashes inside loadNib (inside NSPopAutoreleasePool). Is that expected behavior? Do I need to set up the binding programatically? Can I use an NSObjectController to get around this, as some web search results have implied (but I cannot make work)?

There probably isn't enough here to give a definite answer.

My guess is that the class QuizResults is unknown at compile time, and thus the 'currentScore' property isn't being accessed correctly. Does your code emit any warnings when it is compiled? If so, fix them.

ModeQuizDoc needs at minimum a forward declaration for QuizResults, and the .m file should include QuizResults.h. More importantly, the QuizResults class and its currentScore property needs to be visible to anyone interested in it including IB. I would strongly recommend a property accessor for it instead of relying on accessing the ivar directly. If any code is assuming this property is type id instead of float, you'll probably get the crash that you seem to be getting.

--Graham


_______________________________________________

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: "remote" binding problem
      • From: David Hirsch <email@hidden>
References: 
 >"remote" binding problem (From: David Hirsch <email@hidden>)

  • Prev by Date: Re: Suggest reasons for this crash?
  • Next by Date: Re: "remote" binding problem
  • Previous by thread: "remote" binding problem
  • Next by thread: Re: "remote" binding problem
  • Index(es):
    • Date
    • Thread