• 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: Set string value
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Set string value


  • Subject: Re: Set string value
  • From: "Sherm Pendley" <email@hidden>
  • Date: Wed, 9 Jul 2008 16:21:03 -0400

On Wed, Jul 9, 2008 at 4:12 PM, Kevin Walzer <email@hidden> wrote:
> Hello,
>
> I'm trying to work through an exercise in the new Hillegass book and am
> encountering difficulties. The app fails to build. The relevant code snippet
> is below, with errors noted in the comments:
>
> -(IBAction)getCount:(id)sender
> {
>
>        NSString *string = [textField stringValue];
>        int *stringLength = [string length];  //warning: initialization makes
> pointer from integer without a cast

You've declared stringLength as a pointer to an int, then assigned an
integer value to it. You don't want a pointer here, so leave out he *:

    int stringLength = [string length];

>        [textLabel setStringValue:@"\"%@\" is %d characters long", string,
> stringLength]; //error: too many arguments to function 'setStringValue:'

The -setStringValue: method takes one and only one argument. In
particular, it does *not* take a format string and a variable argument
list, as you appear to expect it to do. To do something like that, you
need to break it into two steps:

    NSString *newString = [NSString localizedStringWithFormat:
@"\"%@\" is %d characters long", string, stringLength];
    [textLabel setStringValue: newString];

sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
_______________________________________________

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: Set string value
      • From: Kevin Walzer <email@hidden>
References: 
 >Set string value (From: Kevin Walzer <email@hidden>)

  • Prev by Date: RE: Set string value
  • Next by Date: Re: Set string value
  • Previous by thread: Re: Set string value
  • Next by thread: Re: Set string value
  • Index(es):
    • Date
    • Thread