• 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: When are bound variables initialized?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: When are bound variables initialized?


  • Subject: Re: When are bound variables initialized?
  • From: Michael Lutz <email@hidden>
  • Date: Wed, 13 Apr 2005 22:21:43 +0200

Yup, I did know that I can't call -setString: on a nil object. I got confused because the variable was initialized after the windows was shown the first time. So I was unsure if I am responsible for alloc] init] it or not.

But your comments cleared things up for me. Now I understand that each change in the views causes an accessor set call for selectedXAxisValue, which makes it clear why it is initialized after the first time the window is shown and why I am safe allocing it myself. The error I mentioned before (the one I got when I tried to alloc it myself) was because I called [selectedXAxisValue dealloc] instead of [selectedXAxisValue release]. That's what you get form late night programming :(

Thanks for your help. Now I am about to figure out why my triggerChangeNotificationsForDependentKey is not working. ;)

Cheers,
  Michael

On Apr 12, 2005, at 22:11, Kevin Ballard wrote:

Umm, you can't call -setString: on a nil object.

I think -awakeFromNib is too late to be setting them directly without using the KVO methods I mentioned or using the setter.

I suggest you set it in your -init method instead. And use

awakeFromNib = [[NSMutableString alloc] initWithString:@"Distance"];

And then in your -dealloc you need to add

[awakeFromNib release];

Don't forget to call [super dealloc] at the end of your -dealloc method.

Also, it's probably not going to work how you expect, using a mutable ivar as the target for an interface binding. Each time you modify the string, you'd have to notify the binding that you changed it with those 2 methods I mentioned earlier, or it won't work. I suggest instead using a regular NSString and just changing it. And if you do that, then you could even simply use [self setValue:@"Distance" forKey:@"selectedXAxisValue"] instead of setting it directly or using those 2 methods I mentioned earlier (the -willChangeValueForKey: and -didChangeValueForKey:)

On Apr 12, 2005, at 4:05 PM, Michael Lutz wrote:

Well, I try to initialize it in awakeFromNib: [selectedXAxisValue setString:@"Distance"];
But at that point of time the Chart window was not displayed the first time. And so selectedXAxisValue is nil and the setString message has no effect.
So my question is: When changes the selectedXAxisValue from nil to a real object? Or do i have to alloc] init] it? I tried it once but I remember I got some signal error when I released it in AppController's dealloc method.

-- Kevin Ballard email@hidden http://www.tildesoft.com http://kevin.sb.org


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: When are bound variables initialized?
      • From: Scott Anguish <email@hidden>
References: 
 >When are bound variables initialized? (From: Michael Lutz <email@hidden>)
 >Re: When are bound variables initialized? (From: Kevin Ballard <email@hidden>)
 >Re: When are bound variables initialized? (From: Michael Lutz <email@hidden>)
 >Re: When are bound variables initialized? (From: Kevin Ballard <email@hidden>)

  • Prev by Date: Re: WWDC2k5 and ROI
  • Next by Date: Re: Rounded selection rectangles in NSTextView (was: NSBezierPath geometry question...)
  • Previous by thread: Re: When are bound variables initialized?
  • Next by thread: Re: When are bound variables initialized?
  • Index(es):
    • Date
    • Thread