Re: Set string value
Re: Set string value
- Subject: Re: Set string value
- From: Kevin Walzer <email@hidden>
- Date: Wed, 09 Jul 2008 16:54:56 -0400
- Organization: WordTech Communications LLC
Sherm Pendley wrote:
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--
Sherm,
Thanks to you and everyone else for the clarifications. I have a lot
experience with scripting languages (Tcl, Python, AppleScript) but am a
relative newbie to C/ObjC.
Regards,
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