On Oct 4, 2008, at 16:39, Thomas Schönfeld wrote:

I used the "example", but the "extra" method setoutString is kinda useless. After a bit thinking I did this.... (see below). I didn't use the "extra" method and it works fine. So my question is, did I just do something not-Cocoa-like and am I still thinking to much C? Did i found a better/shorter way or did I made a fundamental mistake?
...
[outtextField setStringValue:[NSString stringWithFormat: @"%d", [userString length]]];

I don't think you've done anything wrong, nor was the 'setOutString' approach wrong either (since it "conveniently" logged the string too).

However, if you're interested in code brevity, then this is shorter and should produce the same results:

        [outtextField setIntValue: [userString length]];

or, in Objective-C 2.0 syntax:

        outtextField.intValue = userString.length;

which seems, to me at least, quite a lot easier to read than what you started with.

It's worth noting that this whole approach (setting a field in the user interface), though not wrong, is rather un-Cocoa-like. It would be much more usual to define the count of characters as a numeric property (for example), and bind the text field to it, using a numeric formatter to format the number if you wished. But perhaps you are still a couple a chapters away from using bindings.


_______________________________________________

Cocoa-dev mailing list ([email protected])

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]

Reply via email to