• 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: newbie defines and NSString problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: newbie defines and NSString problem


  • Subject: Re: newbie defines and NSString problem
  • From: Larry Fransson <email@hidden>
  • Date: Thu, 11 Mar 2004 14:54:04 -0800

On Mar 11, 2004, at 08:12, Ken Hawkins wrote:

i have a defines.h:

#define FOO "bar"

it always returns me an erro before token ";"

what am i easily overlooking?

You're overlooking the @. Whatever you define FOO to be gets inserted verbatim wherever you put FOO. So if you try this:

#define FOO "bar"
NSString *str = [NSString stringWithString:FOO];

the compiler sees this:

NSString *str = [NSString stringWithString:"bar"];

You see, you forgot the @ - "bar" is not a valid Objective-C string literal, so you get the compiler error.

Try this:

#define FOO @"bar"

and see if it doesn't work better.

Larry Fransson
Seattle, WA
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >newbie defines and NSString problem (From: Ken Hawkins <email@hidden>)

  • Prev by Date: creating files to write data to?
  • Next by Date: Re: resizing a window before displaying, SOLVED
  • Previous by thread: Re: newbie defines and NSString problem
  • Next by thread: I want the NSProgressIndicator to stand still!!!
  • Index(es):
    • Date
    • Thread