• 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: "Abernathy, Joshua" <email@hidden>
  • Date: Wed, 9 Jul 2008 16:19:11 -0400
  • Thread-topic: Set string value

And your line "int *stringLength = [string length];" should not have the
* in front of the variable name. Putting the * in front means it is a
pointer to an int, but -[NSString length] returns just an int.

-----Original Message-----
From: cocoa-dev-bounces+jabernathy=email@hidden
[mailto:cocoa-dev-bounces+jabernathy=email@hidden
] On Behalf Of Alex Wait
Sent: Wednesday, July 09, 2008 4:15 PM
To: email@hidden
Cc: email@hidden
Subject: Re: Set string value

It's this line

[textLabel setStringValue:@"\"%@\" is %d characters long", string,
stringLength];

The setStringValue function does not take more than one argument. If you
want to format the string like that try

[textlabel setStringValue: [NSString stringWithFormat:@"\"%@\" is %d
characters long", string, stringLength] ]

On Wed, Jul 9, 2008 at 1: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
>        [textLabel setStringValue:@"\"%@\" is %d characters long",
string,
> stringLength]; //error: too many arguments to function
'setStringValue:'
>        NSLog(@"%@", string);
> }
>
> The idea is to take input from a text field, calculate the number of
> characters in the text string, and display both the entered text
string and
> the number of characters in a text label.
>
> I'd appreciate it if someone could clarify two things for me:
>
> 1. How to structure the setStringValue method so that gcc doesn't barf
> because of "too many arguments"--I'm not clear what that means.
> 2. How to structure the initialization of the  stringLength variable
so
> that gcc doesn't emit warnings--I'm not clear on what the problem is
here.
>
> TIA,
> Kevin
>
> --
> Kevin Walzer
> Code by Kevin
> http://www.codebykevin.com
> _______________________________________________
>
> 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
>



--
If you can't be kind, at least have the decency to be vague.
_______________________________________________

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:
stics.com

This email sent to email@hidden
_______________________________________________

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

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