8 Replies Latest reply: Oct 14, 2012 7:32 PM by pheonixfire
pheonixfire Level 1 Level 1 (0 points)

I've been trying add a static string to my program but I keep getting the following error:

 

Line Location controller.h:13: error: syntax error before '=' token

 

here's the block of it's from:

@interface controller : NSObject

{

    NSString *myString = @"Text Goes In Here";

    IBOutlet id uppercase;

    IBOutlet id lowercase;

    IBOutlet id left;

    IBOutlet id center;

    IBOutlet id right;

    IBOutlet id slider;

    IBOutlet id textLabel;

    NSMutableString *Change;

    IBOutlet id Label;

    IBOutlet id fontSizeSlider;

    IBOutlet id original;

}

 

As far as I can see the nsstring declared correctly but I keep getting the error

 

any help is appreciated

pheonixfire


xcode, Mac OS X (10.5.8)
  • 1. Re: nsstring problem
    etresoft Level 7 Level 7 (24,270 points)

    There is no support for "static" types in Objective-C beyond what is available in C. To use a static, it has to be outside of any Objective-C declaration and defined as "extern" in the header file. Then add the static variable to the implementation .m file, again outside of the class implementation.

  • 2. Re: nsstring problem
    pheonixfire Level 1 Level 1 (0 points)

    I ment static as in immutable, sorry for the confusion

     

    Any help is appreciated

    pheonixfire

  • 3. Re: nsstring problem
    etresoft Level 7 Level 7 (24,270 points)

    Then make it a read-only property instead. "immutable" is just a horribly general term anyway. Do you mean a constant pointer that can be changed or a non-const pointer to a literal that can't be changed?

     

    Either way, you need to learn the syntax of modern Objective-C. I don't see anything there that wouldn't be better served as a property.

  • 4. Re: nsstring problem
    pheonixfire Level 1 Level 1 (0 points)

    I'm trying to do it the simplest way possible, it's part of a program I'm writing

    as a learning exercise

     

    any help is appreciated

    pheonixfire

  • 5. Re: nsstring problem
    etresoft Level 7 Level 7 (24,270 points)

    If you are learning, then you need to be focused on the future. Turn all of these into properties. Read about the different types of access restrictions and how they work.

  • 6. Re: nsstring problem
    pheonixfire Level 1 Level 1 (0 points)

    I'm trying to get firm a understanding of the basics before moving onto move

    complete methods.

     

    Can you tell me why I'm getting the error for the nsstring when it appears

    to be declared correctly

     

    any help is appreciated

    pheonixfire

  • 7. Re: nsstring problem
    etresoft Level 7 Level 7 (24,270 points)

    It is not declared correctly. You can't give an NSString a value in a header file. You can only do that in an implementation file.

  • 8. Re: nsstring problem
    pheonixfire Level 1 Level 1 (0 points)

    Thankyou for the help

     

    pheonixfire