Re: Set string value
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