Re: Problem with binding of @count

2008-11-28 Thread j o a r


On Nov 28, 2008, at 11:41 PM, Mikael Wämundson wrote:


-(NSString *) numberOfStudents
{
	return [NSString stringWithFormat:@The number of students is: %@,  
[theStudentArrayController  
valueForKeyPath:@[EMAIL PROTECTED]]];

}



I think that it would be more straight forward and efficient to write  
that:


	[NSString stringWithFormat:@The number of students is: %lu,  
((unsigned long)[theStudentArrayController count])];



No error during compilation or run-time, but value in the text label  
is not updated when the array is changed.



That's because you haven't told the bindings machinery that the  
numberOfStudents property depends on the count of objects in the  
array. See:


	http://developer.apple.com/documentation/Cocoa/Conceptual/KeyValueObserving/Concepts/DependentKeys.html 




j o a r


___

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: Problem with binding of @count

2008-11-28 Thread j o a r


On Nov 28, 2008, at 2:49 PM, j o a r wrote:

I think that it would be more straight forward and efficient to  
write that:


	[NSString stringWithFormat:@The number of students is: %lu,  
((unsigned long)[theStudentArrayController count])];



Crap, typo: You'd get the count from the array, and not the  
controller, of course...


j o a r


___

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: Problem with binding of @count

2008-11-28 Thread j o a r


On Nov 28, 2008, at 11:41 PM, Mikael Wämundson wrote:

But I want the number of objects to be part of a text string (The  
number of students is: the value). Thus I put this code into  
myDocument.m:


-(NSString *) numberOfStudents
{
	return [NSString stringWithFormat:@The number of students is: %@,  
[theStudentArrayController  
valueForKeyPath:@[EMAIL PROTECTED]]];

}

No error during compilation or run-time, but value in the text label  
is not updated when the array is changed.



For a simple thing like this you might also use a Pattern Binding:

	http://developer.apple.com/documentation/Cocoa/Reference/CocoaBindingsRef/Concepts/BindingTypes.html 



j o a r


___

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]