Another bindings question

2015-06-02 Thread John Brownie
The exception I was getting was from a binding established in IB, which 
is a bit of a worry, but it prompts me to ask whether I'm pursuing the 
right road.


What I have is an NSTableView (still cell-based, moving to view-based is 
further down the track), and then a bunch of buttons that need to be 
enabled only when there is a selection in the table. Binding to the 
selection property of the array controller with NSNotNil doesn't work. 
Binding to selectionIndexes.count (which works as 0 or 1) does work, but 
this is the binding where I get the exception. Finding that binding was 
trial and error, as I haven't really found a good guide to this whole 
area, so I would be happy to have a better solution.


John
--
John Brownie, john_brow...@sil.org or j.brow...@sil.org.pg
Summer Institute of Linguistics  | Mussau-Emira language, Mussau Is.
Ukarumpa, Eastern Highlands Province | New Ireland Province
Papua New Guinea | Papua New Guinea
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Another bindings question

2015-06-02 Thread John Brownie

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Another bindings question

2015-06-02 Thread Quincey Morris
On Jun 2, 2015, at 17:18 , John Brownie john_brow...@sil.org wrote:
 
 What I have is an NSTableView (still cell-based, moving to view-based is 
 further down the track), and then a bunch of buttons that need to be enabled 
 only when there is a selection in the table. Binding to the selection 
 property of the array controller with NSNotNil doesn't work. Binding to 
 selectionIndexes.count (which works as 0 or 1) does work, but this is the 
 binding where I get the exception. Finding that binding was trial and error, 
 as I haven't really found a good guide to this whole area, so I would be 
 happy to have a better solution.

The most straightforward property to bind the button enabled state to is 
“canRemove”. (It just means something is selected.) It’s easy to miss because 
it’s actually defined in the parent class (NSObjectController), *and* it’s 
apparently missing from the class documentation. However, it’s still documented 
in NSObjectController.h, so it’s really available.

This probably won’t solve your problem. More likely you’ve a place where a 
non-owning reference (weak or unretained, such as for a delegate) is still 
pointing to an invalid object. In some cases, you need to nil out delegate 
references when tearing down your object graph. 



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Core Data bindings question

2011-02-07 Thread Darren Wheatley
Hi,

I have a Core Data app that displays data in a tableView with each column
bound to a field in a core data entity.

One field is called active, and is of type BOOL

I box the BOOL for insertion into the Core Data store using [NSNumber
numberWithBool];

In the TableView I would like to bind the enabled property of each cell
to the active variable, so that if a record has active set to NO all
of the fields become read only.

When I try to bind the  enabled property I get the following error:

cannot create BOOL from object of class __NSArray0

Does anyone have any idea how I can achieve the desired result?

Regards

Darren.



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Bindings Question

2010-09-25 Thread Quincey Morris
On Sep 24, 2010, at 20:09, livinginlosange...@mac.com wrote:

 I have variable in my NSDocument subclass that is bound to the following path 
 _myNSArrayController.selection.subNSArrayController.selection.variableOfInterest.
 
 When I change the subNSArrayController's selection, I don't always see my 
 variable's setters getting called in my NSDocument subclass.

Bound how?


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Bindings Question

2010-09-24 Thread livinginlosangeles
I have variable in my NSDocument subclass that is bound to the following path 
_myNSArrayController.selection.subNSArrayController.selection.variableOfInterest.

When I change the subNSArrayController's selection, I don't always see my 
variable's setters getting called in my NSDocument subclass. WHY?? Its not like 
I'm a binding noob!  Ugh.


Patrick
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Re: NSSearchField and bindings question

2010-01-04 Thread lorenzo7620

On Jan 4, 2010 5:15pm, Saurabh Sharan saurabh.sha...@isharan.com wrote:
You're not alone -- happened to me too. Though, when I downloaded the  
code from pragprog.com, it worked.



- Saurabh



On Sun, Jan 3, 2010 at 10:11 PM, lorenzo7...@gmail.com wrote:


I'm going the Zarra book, Core Data and I;ve reached the section where  
an NSSearchfield is bound to one of the arrays used in the sample  
application (page 43). As instructed in the book, I configured the  
NSSearchfield's predicate binding as follows:




Controller Key: filterPredicate



Model Key Path: name



Display Name: predicate



Predicate Format: keyPath contains $value




This did not work and the NSTableView (column) which should update itself  
from the NSArrayController does nothing.



I found an example of this sort of thing here:



http://homepage.mac.com/mmalc/CocoaExamples/controllers.html




and found that the binding in the second predicate used for the  
NSSearchfield is configured like this:



Controller Key: filterPredicate



Model Key Path :



Display Name: Last Name



Predicate Format: lastName contains[cd] $value





I configured my predicate binding fashion and it works. So my question is:



Did I miss something in the book, or is the book wrong?



Thanks



___





Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)





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:



http://lists.apple.com/mailman/options/cocoa-dev/saurabh.sharan%40isharan.com





This email sent to saurabh.sha...@isharan.com







Thanks for the reply. The downloadable code differs from the book as well:
Controller Key: filterPredicate
Model Key Path:
Display Name: Recipe Name --- Here is one difference, book uses 'predicate'
Predicate Format: name contains[c] $value --- Here is another, book  
uses 'keyPath contains $value'


This works. So, if not anything else, I know of two ways to do this now.
Thanks again.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


NSSearchField and bindings question

2010-01-03 Thread lorenzo7620
I'm going the Zarra book, Core Data and I;ve reached the section where an  
NSSearchfield is bound to one of the arrays used in the sample application  
(page 43). As instructed in the book, I configured the NSSearchfield's  
predicate binding as follows:

Controller Key: filterPredicate
Model Key Path: name
Display Name: predicate
Predicate Format: keyPath contains $value

This did not work and the NSTableView (column) which should update itself  
from the NSArrayController does nothing.

I found an example of this sort of thing here:
http://homepage.mac.com/mmalc/CocoaExamples/controllers.html

and found that the binding in the second predicate used for the  
NSSearchfield is configured like this:

Controller Key: filterPredicate
Model Key Path :
Display Name: Last Name
Predicate Format: lastName contains[cd] $value

I configured my predicate binding fashion and it works. So my question is:
Did I miss something in the book, or is the book wrong?
Thanks
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


To-Many/To-Many Master/Detail Core Data / Bindings Question

2009-12-28 Thread Hunter Hillegas
Howdy,

Trying to crank out a real Cocoa app as an experiment - usually spend my time 
doing Cocoa Touch.

Anyway, I have a pretty simple set of models:

Accounts-Items

I want to setup a screen with a table of accounts. When you click on an 
account, you see a table of items, click on an item, see it's detail. Simple.

My question is if I can do this all with bindings. The table of accounts works 
fine. What I can't seem to figure out is how to limit the 'Items' in the second 
NSTableView to just be the ones associated with the selected account, using 
bindings.

Is there a way to do so? I see I can set a fetch predicate for the 
NSArrayController that is controlling the items but I'm not sure how to 
reference the selected account in the 'account' table view to limit the 
contents of the second NSTableView - if that's even possible... Or 
alternatively, just have the items NSTableView show entities that are in the 
'items' relationship of the selected account. Seems like a pretty simple use 
case but I'm missing the magic.

I can see a path by subclassing NSArrayController but I was hoping to do it all 
with bindings if I could - I just don't know enough to know which way to go or 
if I should just break out the code.

Any help appreciated.

Cheers,
Hunter___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: To-Many/To-Many Master/Detail Core Data / Bindings Question

2009-12-28 Thread Quincey Morris
On Dec 28, 2009, at 15:32, Hunter Hillegas wrote:

 My question is if I can do this all with bindings. The table of accounts 
 works fine. What I can't seem to figure out is how to limit the 'Items' in 
 the second NSTableView to just be the ones associated with the selected 
 account, using bindings.

If I understand your question correctly, the usual way is to bind the detail 
NSArrayController's content via the master NSArrayController's selection 
property. See:


http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CocoaBindings/Tasks/masterdetail.html


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: To-Many/To-Many Master/Detail Core Data / Bindings Question

2009-12-28 Thread Hunter Hillegas
Hi Quincey,

I did read this page - but I'm not sure it does what I want because it's only 
2/3rds of my interface. The master-detail explained there works fine for my 
items list and to display the selected item's properties but I need the list of 
items (the master in Apple's example) to be the result of another relationship 
(the accounts - each account can have zero to many items). So almost as 
master-master-detail, even though that's a terrible term.

Does that make more sense?

On Dec 28, 2009, at 4:14 PM, Quincey Morris wrote:

 On Dec 28, 2009, at 15:32, Hunter Hillegas wrote:
 
 My question is if I can do this all with bindings. The table of accounts 
 works fine. What I can't seem to figure out is how to limit the 'Items' in 
 the second NSTableView to just be the ones associated with the selected 
 account, using bindings.
 
 If I understand your question correctly, the usual way is to bind the detail 
 NSArrayController's content via the master NSArrayController's selection 
 property. See:
 
   
 http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CocoaBindings/Tasks/masterdetail.html
 
 
 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 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:
 http://lists.apple.com/mailman/options/cocoa-dev/lists%40lastonepicked.com
 
 This email sent to li...@lastonepicked.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: To-Many/To-Many Master/Detail Core Data / Bindings Question

2009-12-28 Thread Quincey Morris
On Dec 28, 2009, at 16:19, Hunter Hillegas wrote:

 I did read this page - but I'm not sure it does what I want because it's only 
 2/3rds of my interface. The master-detail explained there works fine for my 
 items list and to display the selected item's properties but I need the list 
 of items (the master in Apple's example) to be the result of another 
 relationship (the accounts - each account can have zero to many items). So 
 almost as master-master-detail, even though that's a terrible term.

Actually, your items are the *detail* for the account, and then possibly the 
master for another detail interface.

So, let's say you have a NSTableView listing accounts, a second NSTableView 
listing items in the accounts list's selection, and a set of text fields, etc 
showing more details of the item(s) selected in the item list.

The accounts list uses a NSArrayController whose content is bound to the 
accounts (array if not Core Data, set if Core Data) in your data model.

Columns in your accounts list would be bound to 
accountsController.arrangedObjects.whateverAccountProperty.

The items list uses a second NSArrayController whose content is bound to 
accountsController.selection.items. This represents the items in the selected 
account, or possibly in the selected accounts. (In NSControllerland, there's 
really no distinction between a single object or multiple objects, until later 
in the process -- each eventual UI element deals with the problem of how to 
display multiple items. There's also an option somewhere that controls how the 
items are merged if there are multiple selected accounts, but if your items are 
unique to an account, the result would be the same.)

Columns in your items list would be bound to 
itemsController.arrangedObjects.whateverItemProperty.

Item detail elements like text fields -- if you want them -- would be bound to 
itemsController.selection.whateverItemProperty. Such user interface elements 
would then display the value of the item selected in the items list. If there 
are multiple items selected, then the binding options for multiple values 
selections kick in.

So your interface is not so much master-master-detail as dual-level 
master-detail.

There's probably an alternative way of approaching this, by programmatically 
maintaining a fetch request for the items array controller, based on monitoring 
the selection of the account array controller, but I can't think of any obvious 
way to do this without writing code. (A few lines of code, but code 
nevertheless.) Chaining array controllers, and using the arrangedObjects or 
selection properties as appropriate, should allow you to design the interface 
codelessly.

Does that sound like what you need? There was a different tutorial that 
explored some of this, but I can't find it any more.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: To-Many/To-Many Master/Detail Core Data / Bindings Question

2009-12-28 Thread Hunter Hillegas
Yes, that's exactly it. Dual level master detail.

For whatever reason, the part I just couldn't see in my head was how to wire up 
the second NSArrayController to accountsController.selection.items.

Thank you so much - just needed that little kick to get to the next step. 
Appreciate it.

On Dec 28, 2009, at 7:38 PM, Quincey Morris wrote:

 On Dec 28, 2009, at 16:19, Hunter Hillegas wrote:
 
 I did read this page - but I'm not sure it does what I want because it's 
 only 2/3rds of my interface. The master-detail explained there works fine 
 for my items list and to display the selected item's properties but I need 
 the list of items (the master in Apple's example) to be the result of 
 another relationship (the accounts - each account can have zero to many 
 items). So almost as master-master-detail, even though that's a terrible 
 term.
 
 Actually, your items are the *detail* for the account, and then possibly the 
 master for another detail interface.
 
 So, let's say you have a NSTableView listing accounts, a second NSTableView 
 listing items in the accounts list's selection, and a set of text fields, etc 
 showing more details of the item(s) selected in the item list.
 
 The accounts list uses a NSArrayController whose content is bound to the 
 accounts (array if not Core Data, set if Core Data) in your data model.
 
 Columns in your accounts list would be bound to 
 accountsController.arrangedObjects.whateverAccountProperty.
 
 The items list uses a second NSArrayController whose content is bound to 
 accountsController.selection.items. This represents the items in the selected 
 account, or possibly in the selected accounts. (In NSControllerland, there's 
 really no distinction between a single object or multiple objects, until 
 later in the process -- each eventual UI element deals with the problem of 
 how to display multiple items. There's also an option somewhere that controls 
 how the items are merged if there are multiple selected accounts, but if your 
 items are unique to an account, the result would be the same.)
 
 Columns in your items list would be bound to 
 itemsController.arrangedObjects.whateverItemProperty.
 
 Item detail elements like text fields -- if you want them -- would be bound 
 to itemsController.selection.whateverItemProperty. Such user interface 
 elements would then display the value of the item selected in the items list. 
 If there are multiple items selected, then the binding options for multiple 
 values selections kick in.
 
 So your interface is not so much master-master-detail as dual-level 
 master-detail.
 
 There's probably an alternative way of approaching this, by programmatically 
 maintaining a fetch request for the items array controller, based on 
 monitoring the selection of the account array controller, but I can't think 
 of any obvious way to do this without writing code. (A few lines of code, but 
 code nevertheless.) Chaining array controllers, and using the arrangedObjects 
 or selection properties as appropriate, should allow you to design the 
 interface codelessly.
 
 Does that sound like what you need? There was a different tutorial that 
 explored some of this, but I can't find it any more.
 
 
 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 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:
 http://lists.apple.com/mailman/options/cocoa-dev/lists%40lastonepicked.com
 
 This email sent to li...@lastonepicked.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Bindings question...

2009-12-13 Thread Keary Suska
On Dec 12, 2009, at 2:37 PM, Quincey Morris wrote:

 2. Bindings that we set in IB, such as NSTableColumn's value binding, are 
 what the documentation calls Cocoa bindings, as opposed to just plain 
 bindings. Presumably, all Cocoa bindings have the ability to recognize 
 certain predefined keys (selection, arrangedObjects, etc -- probably the 
 same list of keys that pops up at the controller key field in IB) as the 
 first component of the key path.

Some clarifications may be in order. As this is the Cocoa list, and there is no 
other use of the term binding in Cocoa other than Cocoa bindings, IMHO I 
think it best to encourage every poster to only use the term binding (of any 
conjugation) to refer to Cocoa Bindings.

The predefined keys are not a function of bindings, they are simply 
properties of the controller class(es). The list in IB just happens to be those 
keys that the specific selected NSObjectController subclass implements. This is 
a feature of IB, rather than any function of bindings per se. It will be 
empty/disabled for any other class. 

Best,

Keary Suska
Esoteritech, Inc.
Demystifying technology for your home or business

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Bindings question...

2009-12-13 Thread Matt Neuburg
On or about 12/12/09 12:02 PM, thus spake
cocoa-dev-requ...@lists.apple.com cocoa-dev-requ...@lists.apple.com:

 Date: Sat, 12 Dec 2009 13:03:02 -0600
 From: Jim Majure jim.maj...@mac.com
 Subject: Bindings question...
 
 What I don't understand is how the TableColumn is
 specifying the particular instance in the arrangedObjects array that
 was changed.

I find myself unable to make any sense of the question, but, thinking about
what you could possibly mean, a couple of thoughts occur to me:

(1) arrangedObjects is merely a presentation layer, as it were. Are you
confusing arrangedObjects with content?

(2) When thinking about what tables automatically do, are you taking into
account the selection?

m.

-- 
matt neuburg, phd = m...@tidbits.com, http://www.tidbits.com/matt/
pantes anthropoi tou eidenai oregontai phusei
Among the 2007 MacTech Top 25, http://tinyurl.com/2rh4pf
AppleScript: the Definitive Guide, 2nd edition
http://www.tidbits.com/matt/default.html#applescriptthings
Take Control of Exploring  Customizing Snow Leopard
http://tinyurl.com/kufyy8
RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
TidBITS, Mac news and reviews since 1990, http://www.tidbits.com



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Bindings question...

2009-12-12 Thread Quincey Morris
On Dec 12, 2009, at 11:03, Jim Majure wrote:

 I have a question regarding bindings: when I bind the value of a TableColumn 
 to a controller, I specify the key path as something like this: 
 @arrangedObjects.name. So each row of the table, displays the name field 
 from an object in the arrangedObjects property of the controller. In the IB 
 it's actually broken into the controller key, arrangedObjects, and the 
 keypath, name, though i don't see how this impacts the 
 bind:toObject:withKeyPath:options: method.
 
 When I modify a value in a view, I send the setValue:forKey: message to the 
 controller. What I don't understand is how the TableColumn is specifying the 
 particular instance in the arrangedObjects array that was changed. If I 
 just say this:
 
   [controller setValue:@new value forKey:@arrangedObjects.name]
 
 the specific instance is not specified. What is actually happening under the 
 covers here?
 
 One possibility I can think of is that it uses the collection accessor 
 pattern (objectInKeyAtIndex:) to retrieve the object, then use the 
 setValue:forKey: on the individual object.

It's kind of mysterious, but I'm prepared to take some wild guesses hoping that 
someone who knows more will jump in and correct/educate me.

There are a couple of pieces to consider:

1. While a table column represents an entire list of values, a NSTableColumn 
really only represents a single value (via its single cell). It *appears* to 
represent the entire list by representing different values at different times.

2. Bindings that we set in IB, such as NSTableColumn's value binding, are 
what the documentation calls Cocoa bindings, as opposed to just plain 
bindings. Presumably, all Cocoa bindings have the ability to recognize 
certain predefined keys (selection, arrangedObjects, etc -- probably the 
same list of keys that pops up at the controller key field in IB) as the first 
component of the key path.

3. When sent to a NSArray, 'valueForKey:' returns an array of the values of the 
key for each component element. [It's not clear whether NSTableColumn ever uses 
this mechanism, though.]

4. When sent to a NSArray, 'setValue:forKey:' sets the value of each component 
element to the same thing. [But it's unlikely this has any relevance to 
NSTableColumn -- it's more relevant to changing multiple values displayed in 
text fields, I think.]

So I suspect that NSTableColumn, via Cocoa bindings, decomposes the binding key 
path into a reference to the NSArrayController and a model key, and effectively 
does something like:

[[[controller valueForKey: @arrangedObjects] objectAtIndex: 
currentRow]  setValue: newValue forKeyPath: @name];

It may do a similar thing for getting values, or it may make some use of #3 
above. It must also (presumably) register as an observer of arrangedObjects 
as well as the values of (some) individual objects, but it's not clear 
precisely what the pattern of observers is.

Are you trying to bind Cocoa objects with Cocoa bindings, or do your objects 
have a home-grown bindings implementation? If the latter, you might have a bit 
of work to do, reinventing the Cocoa bindings behavior.

[I'll use this opportunity to get back on my soapbox and reiterate my opinion 
that NSController and its demon offspring are truly horrible classes from the 
developer's point of view. Their API behavior is no more and no less than 
whatever behavior they happen to implement (in a properly designed class, the 
implementation serves the API contract, not dominates it), and we're not told 
what that behavior is, beyond a few vague generalities. We learn how to use 
them by memorizing a few usage patterns that happen to work, and when we 
overstep the bounds, things fail mysteriously, with at best a highly detailed 
exception error message that is completely inscrutable.]


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


NSValueTransformer/Cocoa Bindings question

2009-05-27 Thread Kelvin Chung
I'm having trouble using an NSValueTransformer.  Suppose I have an  
NSArrayController foo.  If I bind a label's value to selection.number  
(which is an NSNumber) on foo, then this is fine.  However, I'm having  
trouble when it comes to transforming this value.


Suppose I have a second NSArrayController bar, whose content array  
binding is set to selection.number on foo, but with an  
NSValueTransformer transforming it into an NSArray.  However, once I  
try to test this out, I get a crash, with this:


*** Terminating app due to uncaught exception 'NSUnknownKeyException',  
reason: '[NSTableView 0x12a180 valueForUndefinedKey:]: this class is  
not key value coding-compliant for the key number.'


Two perplexing this come to mind: the only NSTableView I have is for a  
table whose columns are bound to foo (arrangedObjects.number), which  
works normally without the binding on bar.  Second, I fail to see why  
the binding on bar fails when the binding on the label works.  The  
only thing I can think of is that there is an array key expected where  
only a single key was given.  Why is this, and how can I solve this?


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Bindings Question

2008-09-25 Thread Eric Lee
I have an app that I'm making for practice that has a tableview, and a  
text field (and many other things, but the ones that are the problem  
are these two)


I just successfully changed my app to use bindings. However, whenever  
I pressed a button before, something would be added into a  
NSMutableArray, and then the string would show up in the table view.


Now, something IS added into the NSmutableArray, and will show up, but  
not the string. The thing that's added is just this blank.


How do you solves these so that when I press the button, the string in  
the text field will actually be added and shown in the table view?


Thanks!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Bindings Question

2008-09-25 Thread Chris Idou

Normally you would have the table controlled by a NSArrayController. You would 
bind the button to an action method which would take the value from the text 
field and pass it to addObject: method of the array controller.


--- On Thu, 9/25/08, Eric Lee [EMAIL PROTECTED] wrote:

 From: Eric Lee [EMAIL PROTECTED]
 Subject: Bindings Question
 To: Cocoa-dev@lists.apple.com
 Date: Thursday, September 25, 2008, 5:34 PM
 I have an app that I'm making for practice that has a
 tableview, and a  
 text field (and many other things, but the ones that are
 the problem  
 are these two)
 
 I just successfully changed my app to use bindings.
 However, whenever  
 I pressed a button before, something would be added into a 
 
 NSMutableArray, and then the string would show up in the
 table view.
 
 Now, something IS added into the NSmutableArray, and will
 show up, but  
 not the string. The thing that's added is just this
 blank.
 
 How do you solves these so that when I press the button,
 the string in  
 the text field will actually be added and shown in the
 table view?
 
 Thanks!
 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 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:
 http://lists.apple.com/mailman/options/cocoa-dev/idou747%40yahoo.com
 
 This email sent to [EMAIL PROTECTED]


  
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Bindings Question

2008-09-25 Thread Eric Lee

Sorry for the late response...computer froze

Anyways, yeah, I have a NSArrayController, and I binded the table view  
to it, which let me actually add something. How do you bind a button  
to an action? Just control-drag?

On Sep 25, 2008, at 7:39 PM, Chris Idou wrote:



Normally you would have the table controlled by a NSArrayController.  
You would bind the button to an action method which would take the  
value from the text field and pass it to addObject: method of the  
array controller.



--- On Thu, 9/25/08, Eric Lee [EMAIL PROTECTED] wrote:


From: Eric Lee [EMAIL PROTECTED]
Subject: Bindings Question
To: Cocoa-dev@lists.apple.com
Date: Thursday, September 25, 2008, 5:34 PM
I have an app that I'm making for practice that has a
tableview, and a
text field (and many other things, but the ones that are
the problem
are these two)

I just successfully changed my app to use bindings.
However, whenever
I pressed a button before, something would be added into a

NSMutableArray, and then the string would show up in the
table view.

Now, something IS added into the NSmutableArray, and will
show up, but
not the string. The thing that's added is just this
blank.

How do you solves these so that when I press the button,
the string in
the text field will actually be added and shown in the
table view?

Thanks!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/idou747%40yahoo.com

This email sent to [EMAIL PROTECTED]




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/ericlee1994%40gmail.com

This email sent to [EMAIL PROTECTED]


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Very basic Bindings question

2008-09-24 Thread Jason Coco


On Sep 24, 2008, at 04:21 , Adil Saleem wrote:


Hi,

I am trying to use bindings for the first time. So this is a pretty  
basic question.


As an example what i am trying to do is that i have a NSTextField in  
which user enters some numeric value. I have a int type variable in  
my class that is binded to the value field of this text field. I get  
the value in the variable correctly. But the problem is that the  
accessor method that i have written are not called. If i print  
something in the accessor methods, it is not printed on the console.


Here is the code.


I have declared in myClass.h

@interface myClass: NSObject {

 int Var;
}

-(void)setVar:(int)aNumber;
-(int)getVar;


Don't use getVar (also, don't start a variable with a capital  
letter)... the correct naming convention is this:


@interface MyClass : NSObject {	// the convention is to start class  
names with a capital letter

int var;
}

-(void)setVar:(int)aNumber;		// the setter message should be the word  
set + [capital first letter] + rest of variable name
-(int)var;			// the getter message should have the same name as  
the variable


HTH, Jason

smime.p7s
Description: S/MIME cryptographic signature
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Re: Very basic Bindings question

2008-09-24 Thread Raphael Sebbe
file:///Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/Cocoa/Conceptual/KeyValueCoding/Concepts/Compliant.htmlfile:///Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/Cocoa/Conceptual/KeyValueCoding/Concepts/Compliant.html
Hi,
here is how accessors should be defined. Watch the case too.

file:///Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/Cocoa/Conceptual/KeyValueCoding/Concepts/Compliant.html

HTH

Raphael

On Wed, Sep 24, 2008 at 10:21 AM, Adil Saleem [EMAIL PROTECTED]wrote:

 Hi,

 I am trying to use bindings for the first time. So this is a pretty basic
 question.

 As an example what i am trying to do is that i have a NSTextField in which
 user enters some numeric value. I have a int type variable in my class
 that is binded to the value field of this text field. I get the value in the
 variable correctly. But the problem is that the accessor method that i have
 written are not called. If i print something in the accessor methods, it is
 not printed on the console.

 Here is the code.


 I have declared in myClass.h

 @interface myClass: NSObject {

  int Var;
 }

 -(void)setVar:(int)aNumber;
 -(int)getVar;

 In the myClass.m i have

 @implementation myClass

 -(void)setVar:(int)aNumber {

Var = aNumber;
 }

 -(int)getVar
 {
 return Var;
 }


  Why are these functions not being called ? Am i missing something in the
 syntax or is it something else.


 Thanx






 ___

 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

 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:
 http://lists.apple.com/mailman/options/cocoa-dev/raphael.sebbe%40gmail.com

 This email sent to [EMAIL PROTECTED]

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Seemingly Simple Bindings Question

2008-08-31 Thread Jamie Phelps
I have an NSPopUpButton with five menu items: WTD, MTD, QTD, YTD, and  
Specific Dates. What I want to do is show and hide two labels and  
textfields for Start Date and End Date depending on if the Specific  
Dates option is selected.


My first attempt was to do

@property (readonly) BOOL specifyingDateRange;

-(BOOL)specifyingDateRange{
if([dateRangePopUp indexOfSelectedItem] == 4){
return YES;
}
return NO;
}

but this is not working correctly.

Can anyone explain what the correct implementation is and possibly  
what mistake I made in assessing the problem?


Thanks in advance,
Jamie
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Seemingly Simple Bindings Question

2008-08-31 Thread Graham Cox


On 1 Sep 2008, at 9:38 am, Jamie Phelps wrote:

I have an NSPopUpButton with five menu items: WTD, MTD, QTD, YTD,  
and Specific Dates. What I want to do is show and hide two labels  
and textfields for Start Date and End Date depending on if the  
Specific Dates option is selected.


My first attempt was to do

@property (readonly) BOOL specifyingDateRange;

-(BOOL)specifyingDateRange{
   if([dateRangePopUp indexOfSelectedItem] == 4){
   return YES;
   }
   return NO;
}

but this is not working correctly.

Can anyone explain what the correct implementation is and possibly  
what mistake I made in assessing the problem?



You probably don't want to tie the functionality to a specific item  
index - it makes it hard to easily change the UI without breaking (or  
needing to revise) the code. Instead, you could use a tag value to  
represent the item's function, or possibly its representedObject.


Not being familiar with bindings, I can't be sure how this relates to  
that, but more conventionally you'd set an action and target for your  
pop-up menu and the action's signature would look like:


- (IBAction)respondToDateRangePopUp:(id) sender
{
if([sender tag] == kTheTagImLookingFor)
[self doSomething];
}


hth,

Graham
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Seemingly Simple Bindings Question

2008-08-31 Thread Ken Thomases

On Aug 31, 2008, at 6:38 PM, Jamie Phelps wrote:

I have an NSPopUpButton with five menu items: WTD, MTD, QTD, YTD,  
and Specific Dates. What I want to do is show and hide two labels  
and textfields for Start Date and End Date depending on if the  
Specific Dates option is selected.


My first attempt was to do

@property (readonly) BOOL specifyingDateRange;

-(BOOL)specifyingDateRange{
   if([dateRangePopUp indexOfSelectedItem] == 4){
   return YES;
   }
   return NO;
}

but this is not working correctly.

Can anyone explain what the correct implementation is and possibly  
what mistake I made in assessing the problem?


It's hard to know without more details.

My suspicion is that you haven't arranged for any KVO change  
notification to be sent out when this property changes its value.  KVO  
and Bindings do not poll the properties of objects to check if they've  
changed.  There has to be an affirmative notification sent out to  
observers telling them that the property may have changed.  That  
notification is triggered by a message to the object which has the  
property -- either a KVO-compliant setter (preferred) or a pair of  
willChange…/didChange… messages (last resort if your design  
absolutely can't conform to the normal way of doing things).


I assume the above method is in your controller.  It certainly  
shouldn't be in the model.  However, is the mode implied by the pop-up  
expressed in the model?  And is the pop-up's selection bound through  
the controller to that model property?  If so, then I'd recode that  
method to depend on the model property instead of the pop-up view's  
state.  And then I'd use a  
+keyPathsForValuesAffectingSpecifyingDateRange method to inform KVO  
that when the model property changes, that implies a change in the  
specifyingDateRange property of the controller.


If somehow the mode implied by the pop-up isn't a model property, then  
I'd make it a controller property.  You'd still bind the pop-up's  
selection to it, and you'd still use  
+keyPathsForValuesAffectingSpecifyingDateRange to inform the KVO  
system that the two properties are interrelated.


Cheers,
Ken___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: basic bindings question

2008-05-15 Thread Daniel Child
You were right, it accidentally switched to user defaults. Removing  
that and setting it back to controller still leads to a runtime  
exception.


2008-05-15 22:30:53.718 StringBinding[290:10b] An uncaught exception  
was raised
2008-05-15 22:30:53.719 StringBinding[290:10b] [NSApplication  
0x119650 valueForUndefinedKey:]: this class is not key value coding- 
compliant for the key values.
2008-05-15 22:30:53.723 StringBinding[290:10b] *** Terminating app due  
to uncaught exception 'NSUnknownKeyException', reason:  
'[NSApplication 0x119650 valueForUndefinedKey:]: this class is not  
key value coding-compliant for the key values.'

2008-05-15 22:30:53.723 StringBinding[290:10b] Stack: (
2449281611,
2445869307,
2449280369,

Under bindings, Values shows that it is set to Controller.number. I  
have set up conventional accessors. Under setNumber: I also try to  
bounce the value back to an outlet text field using


[valueField setStringValue: [self number] stringValue];

But it doesn't even run. I am not clear why it is claiming NSApp is  
not key value coding-compliant when I set up the binding to the  
controller object.


On May 15, 2008, at 12:54 AM, Ken Thomases wrote:

This seems to have nothing to do with the above code.  First, the  
key involved is called values not number.  Second, the receiver  
is the NSApplication instance.  So, why is something trying to  
access a non-existent values property of the NSApplication class?


NSUserDefaultsController has a values property.  I wonder if you  
temporarily had a binding to that which you attempted to redirect  
toward File's Owner but you didn't change it properly.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


basic bindings question

2008-05-14 Thread Daniel Child

Hi All,

I'm trying to get my feet wet with bindings and want to try something  
simpler than the mail example provided online.


All I'm trying to do is to replace the target-action-outlet approach  
with bindings in the simplest case I can think of: a text field whose  
value would correspond to an ivar in the controller. One text field  
would receive the number, a button would click, pass the number to the  
ivar, and redisplay that value in another text field.


First off, is it possible possible to bind directly to an instance  
variable in the controller? In my hyper-basic example, I'm collapsing  
M and C. I thought doing so should be OK, so I tried:


Bind to: Controller
Model Key Path: self.number (number is the ivar) (self presumably  
being the controller)


This didn't work.

Unfortunately, I am also confused about the intended receiver for  
addObserver: forKeyPath:. I thought it would be the ivar (number), but  
I get a warning that NSNumber may not respond to that method (and sure  
enough the docs show that it doesn't). Logically, the second text  
field should observe that the model/controller ivar (number) has  
changed. But I thought you were not supposed to use outlets either.


Does this mean you can only use bindings for arrays? Clearly that  
can't be right


If anyone knows of a hyper-simple example dispensing with tables and  
arrays, I'd really appreciate the link


Thanks.

Daniel
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: basic bindings question

2008-05-14 Thread Ken Thomases

On May 14, 2008, at 2:08 PM, Daniel Child wrote:
All I'm trying to do is to replace the target-action-outlet  
approach with bindings in the simplest case I can think of: a text  
field whose value would correspond to an ivar in the controller.  
One text field would receive the number, a button would click, pass  
the number to the ivar, and redisplay that value in another text  
field.


Actually, requiring the button click to perform the transfer is going  
to make it harder.  It will be easier to just have the field directly  
update the ivar when editing completes.


First off, is it possible possible to bind directly to an instance  
variable in the controller? In my hyper-basic example, I'm  
collapsing M and C. I thought doing so should be OK, so I tried:


Bind to: Controller
Model Key Path: self.number (number is the ivar) (self presumably  
being the controller)


This didn't work.


Leave out the self..  Just use number.


Unfortunately, I am also confused about the intended receiver for  
addObserver: forKeyPath:. I thought it would be the ivar (number),  
but I get a warning that NSNumber may not respond to that method  
(and sure enough the docs show that it doesn't). Logically, the  
second text field should observe that the model/controller ivar  
(number) has changed. But I thought you were not supposed to use  
outlets either.


There are two common misconceptions here:

1) KVO is not for observing properties, as such.  It's for observing  
the object which _has_ the property.  To put it another way: I don't  
observe the number, I observe the controller for changes in its  
number property.


2) A property is _not_ the ivar.  The ivar, if it exists at all, is  
an implementation detail of how the class implements the property.  A  
property is part of the interface of the object.  You will find it  
much easier if you conceptualize a property as the set of KVC- 
conforming methods in the object's interface.  A key is a string  
naming or identifying a property.  (Yes, KVC and KVO provide built-in  
support for properties which don't have accessor methods.  They will  
access the ivar directly.  However, this is just a convenience and a  
fall-back position.  It doesn't materially change how you should  
conceptualize properties.)


To illustrate:

@interface Foo : NSObject
{
NSNumber* number;   //  --  This is NOT the property
}

// _These_ are the property:
- (NSNumber*) number;
- (void) setNumber:(NSNumber*)newNumber;

@end


// ... in some other code somewhere

Foo* myFoo = /* ... */
[myFoo addObserver:self forKeyPath:@number];

This object (self) is observing the myFoo object for changes in its  
number property.



Think also about the KVO notifications you will receive:

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id) 
object change:(NSDictionary *)change context:(void *)context;


Think about what you will be receiving in the object parameter of  
that.  You're not interested in knowing that some anonymous, free- 
floating NSNumber object has changed; you need to be informed which  
object has had its number property changed.  So, in this case, it  
would be the Foo object which was myFoo in the above snippet.  That's  
why you need to conceptualize KVO as observing the object which has  
the property, not as observing the property (or ivar) itself.


Consider the possibility that I use a plain int instead of an  
NSNumber as the backing store for the number property of a Foo.   
Surely, the object parameter of the observeValueForKeyPath...  
method can't be that int, because an int isn't an object.   
Furthermore, consider if there is _no_ backing storage for the number  
property of a Foo.  What if I changed the above @interface to omit  
the number ivar.  Foo still has a number property.  Its meaning/ 
value is whatever results from the semantics of the two methods - 
number and -setNumber:.  In theory, they could compute the value on  
the fly, call some library API, or even query a remote server to  
determine the value.  They could do anything and it need not involve  
an ivar of any sort.



Lastly, I want to address a confusion that I've seen at other times  
on this list (but which you didn't express).  Often people have a  
class with an NSMutableArray ivar, and they get confused as to why  
modifications that they make directly to that ivar (as by - 
addObject:, for example) don't result in KVO notifications and  
updates to the bound GUI elements.  The reason is that nothing is  
observing that array.  They are observing the owning object for  
changes of the property for which that ivar is backing storage.


The array does not (and can not) send out KVO notifications.  For one  
thing, it doesn't know what object owns it nor what property it  
represents.  The owning object is what sends out the KVO  
notifications.  In order for it to do that, the owning object must be  
messaged.  It might be messaged with a KVC-conforming setter such 

Re: basic bindings question

2008-05-14 Thread Ken Thomases

On May 14, 2008, at 10:54 PM, Daniel Child wrote:
If I want to observe the property of an object, and in my case, it  
turns out that the M and C are collapsed into a model-controller,  
then it's basically a case of asking something to observe itself.


Well, it is sometimes desirable for an object to observe itself for  
changes to its properties.  However, it is often not necessary.  In  
particular, an object's properties should only be modified by  
messaging the object, which gives you a perfect way to notice that  
the change is being made -- right in the method which is invoked by  
the message.


For example, if your controller's number property is being changed,  
then something should be invoking its -setNumber: method.  In that  
case, you can just add your code for coping with a change to that  
method:


- (void) setNumber:(NSNumber*)newNumber
{
if (newNumber != number  ![number isEqualToNumber:newNumber])
{
[number release];
number = [newNumber retain];
// Add code to cope with a change in the number property here
}
}


Can you be more specific about why you want your controller to  
observe its own number property?  What are you trying to accomplish?   
I suspect there's another way to accomplish what you're interested in.



In other words, your myFoo addObserver: self THE CONTROLLER  
forKeyPath: @number becomes


- (void) awakeFromNib {
	[self addOberver: self forKeyPath: @number options: 0 context:  
NULL];


There's a typo there.  You've missed the s in addObserver.


}

I tried that and got the same message as before (receiver may not  
respond to addObserver), only this time the receiver is the  
controller instead of number.


Can you report the exact message you're getting?  Is it a compile- 
time warning or a run-time exception?



Is it not possible to collapse M and C for a case where you want to  
track a simple text field. It seems it must be.


It is possible.  We'll have to see what's going wrong in your  
particular case.


Cheers,
Ken
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: basic bindings question

2008-05-14 Thread Daniel Child


On May 15, 2008, at 12:09 AM, Ken Thomases wrote:

Can you be more specific about why you want your controller to  
observe its own number property?  What are you trying to  
accomplish?  I suspect there's another way to accomplish what you're  
interested in.
I'm simply trying to reduce bindings to the most basic case: type into  
a text field, have that value observed, and then reflect it somewhere  
else (as in another text field). The actual application I have in mind  
uses text fields to enable the user to specify sort fields, and rather  
than have a bunch of methods to check those values prior to sorting, I  
thought I could use bindings to automatically have those values set as  
soon as the user types them in. (I've used textDidChange in the past  
to accomplish something similar, but I thought this would be an easy  
case to try bindings. Especially since I might want to provide a more  
elegant interface for specifying sort fields prior to the sort.


In other words, your myFoo addObserver: self THE CONTROLLER  
forKeyPath: @number becomes


- (void) awakeFromNib {
	[self addOberver: self forKeyPath: @number options: 0 context:  
NULL];


There's a typo there.  You've missed the s in addObserver.

Oops. Sorry about that, but I get a runtime error all the same:

[NSApplication 0x119640 valueForUndefinedKey:]: this class is not  
key value coding-compliant for the key values.
2008-05-15 00:32:19.909 StringBinding[564:10b] *** Terminating app due  
to uncaught exception 'NSUnknownKeyException', reason:  
'[NSApplication 0x119640 valueForUndefinedKey:]: this class is not  
key value coding-compliant for the key values.'


Thanks!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: basic bindings question

2008-05-14 Thread Ken Thomases

On May 14, 2008, at 11:43 PM, Daniel Child wrote:


On May 15, 2008, at 12:09 AM, Ken Thomases wrote:

Can you be more specific about why you want your controller to  
observe its own number property?  What are you trying to  
accomplish?  I suspect there's another way to accomplish what  
you're interested in.
I'm simply trying to reduce bindings to the most basic case: type  
into a text field, have that value observed, and then reflect it  
somewhere else (as in another text field). The actual application I  
have in mind uses text fields to enable the user to specify sort  
fields, and rather than have a bunch of methods to check those  
values prior to sorting, I thought I could use bindings to  
automatically have those values set as soon as the user types them  
in. (I've used textDidChange in the past to accomplish something  
similar, but I thought this would be an easy case to try bindings.  
Especially since I might want to provide a more elegant interface  
for specifying sort fields prior to the sort.


First, bindings are implemented using KVO, but KVO is not the same as  
bindings.


Second, to do what you're talking about, you'd bind the text field's  
value binding to the controller-model.  There's no reason to have the  
controller observe its own property in this scenario.


Third, while you can definitely set bindings up in code, that's not  
reduc[ing] bindings to the most basic case.  Setting the binding up  
via IB is the most basic case.



In other words, your myFoo addObserver: self THE CONTROLLER  
forKeyPath: @number becomes


- (void) awakeFromNib {
	[self addOberver: self forKeyPath: @number options: 0 context:  
NULL];


There's a typo there.  You've missed the s in addObserver.

Oops. Sorry about that, but I get a runtime error all the same:

[NSApplication 0x119640 valueForUndefinedKey:]: this class is not  
key value coding-compliant for the key values.
2008-05-15 00:32:19.909 StringBinding[564:10b] *** Terminating app  
due to uncaught exception 'NSUnknownKeyException', reason:  
'[NSApplication 0x119640 valueForUndefinedKey:]: this class is  
not key value coding-compliant for the key values.'


This seems to have nothing to do with the above code.  First, the key  
involved is called values not number.  Second, the receiver is  
the NSApplication instance.  So, why is something trying to access a  
non-existent values property of the NSApplication class?


NSUserDefaultsController has a values property.  I wonder if you  
temporarily had a binding to that which you attempted to redirect  
toward File's Owner but you didn't change it properly.


-Ken
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]