• 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: wasting space?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: wasting space?


  • Subject: Re: wasting space?
  • From: Quincey Morris <email@hidden>
  • Date: Sat, 4 Oct 2008 22:54:48 -0700

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@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: wasting space?
      • From: "Michael Ash" <email@hidden>
    • Re: wasting space?
      • From: Uli Kusterer <email@hidden>
References: 
 >wasting space? (From: Thomas Schönfeld <email@hidden>)

  • Prev by Date: Re: Memory Leak in XIB file?
  • Next by Date: Binding to @count
  • Previous by thread: wasting space?
  • Next by thread: Re: wasting space?
  • Index(es):
    • Date
    • Thread