• 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
Newbie Bindings questions: Alarm clock application
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Newbie Bindings questions: Alarm clock application


  • Subject: Newbie Bindings questions: Alarm clock application
  • From: Greg Hurrell <email@hidden>
  • Date: Mon, 8 May 2006 12:18:48 +0200

I'm not a Cocoa newbie but I *am* a bindings newbie. Ever since bindings came out I've been trying to get my head wrapped around them without success. I am currently trying to put together an alarm clock application as a way of teaching myself about bindings. Unfortunately, things that I would have thought would be easy with bindings are not proving to be easy (or possible) at all, and I'm wondering if I am trying to use bindings in ways in which they were not intended to be used. I have a few doubts and questions.

I began by setting up a window in Interface Builder. I added some checkboxes for things like whether the alarm timer should repeat or not, a pop-up menu for choosing what should happen when the alarm goes off, a slider or an NSDatePicker for choosing when the alarm should go off etc. This was before writing a single line of code. My plan was to start hooking things up with bindings and writing code as needed along the way.

The only thing I've ever had success with with bindings up until now is using NSUserDefaultsController, but this little app doesn't have any preferences. I've also checked out the many NSTableView-related examples at http://homepage.mac.com/mmalc/CocoaExamples/ controllers.html but this app doesn't have any NSTableViews either.

The first code I wrote was a model class that contains all the information about the timer window with instance variables for each aspect of it. An NSDate for storing the "fire date", NSNumbers for storing boolean values like whether it should repeat or not (I used NSNumber instead of a simple BOOL because it seems that bindings is built for objects, not scalars).

But my first doubt is that in order to bind any of this stuff in my nib I had to instantiate multiple NSObjectControllers. For example, one for the "fire date", one for each check box etc. I would have thought that I could just use a single controller, seeing as I have a single model class behind the scenes, and somehow access the instance variables of that model class via that single controller. But no, the only way I can get it to work is to have a dedicated controller for each instance variable. This just seems wrong. Am I doing this in completely the wrong way?

Basically, in each NSObjectController I set the contentObject to bind to my model class, and I use the instance variable name as the "model path". Then I bind the views to the controller with the controller key set to "content" and the model key path left blank. This works but it feels wrong to have separate controllers for every instance variable. I've tried to throw out all these separate controllers and just use a single one but I can't get it to work, either binding to "content" or following the pattern used by NSUserDefaultsController and binding to "values". The other thing I note is that because you *have* to define a "model path" I can no longer just pick a single instance variable; so that forced me to create a new NSMutableDictionary instance variable and use that instead, packing all the other variables that were previously instance variables into the dictionary. I'd be prepared to persist with this if I didn't have so many doubts about the validity of it from a design standpoint (and not even knowing if it will be possible to make it work). Basically I just need someone to give me a hint about how the heck I should be proceeding.

I also can't seem to achieve even very simple stuff with bindings, like enabling/disabling checkboxes depending on which radio button is selected in an NSMatrix. Everyone sings the praises of bindings and how it enables them to get rid fo their glue code, but I just can't get this to work and I'm going to end up writing old-fashioned glue code anyway!

And finally, I'm totally confused about how I should handle multiple alarm clock windows at once. Should I be worrying about NSWindowController, NSDocument etc? I've read the documentation on document-based apps and am not sure what to do because the alarm clock windows aren't technically documents (I certainly have no intention of saving or printing them) but I'd like to be able to have multiple such windows in my little test app. From the architectural/ design standpoint, what Cocoa design patterns and classes should I be thinking about using here?

Sorry that I don't have any more specific questions. I basically just need some reassurance and to be pointed in the right direction. I've spent many many hours experimenting, poring over sample code, reading the list archives, and I *still* feel totally ignorant about bindings. I'm hoping someone with experience can give me a nudge in the direction that I should be going.

Cheers,
Greg


Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
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: Newbie Bindings questions: Alarm clock application
      • From: Mike Abdullah <email@hidden>
  • Prev by Date: Re: Application for Specific Processors
  • Next by Date: Re: Newbie Bindings questions: Alarm clock application
  • Previous by thread: Re: Application for Specific Processors
  • Next by thread: Re: Newbie Bindings questions: Alarm clock application
  • Index(es):
    • Date
    • Thread