• 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: 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


References: 
 >Set string value (From: Kevin Walzer <email@hidden>)
 >Re: Set string value (From: "Sherm Pendley" <email@hidden>)

  • Prev by Date: Re: Making a text cell in a table editable
  • Next by Date: Calling autorelease on CFAllocated objects?
  • Previous by thread: Re: Set string value
  • Next by thread: Re: Set string value
  • Index(es):
    • Date
    • Thread