Skip navigation

nsstring problem

505 Views 8 Replies Latest reply: Oct 14, 2012 7:32 PM by pheonixfire RSS
pheonixfire Calculating status...
Currently Being Moderated
Oct 12, 2012 2:09 AM

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)
  • etresoft Level 7 Level 7 (23,880 points)
    Currently Being Moderated
    Oct 12, 2012 6:41 AM (in response to pheonixfire)

    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.

  • etresoft Level 7 Level 7 (23,880 points)
    Currently Being Moderated
    Oct 12, 2012 8:28 AM (in response to pheonixfire)

    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.

  • etresoft Level 7 Level 7 (23,880 points)
    Currently Being Moderated
    Oct 14, 2012 2:08 PM (in response to pheonixfire)

    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.

  • etresoft Level 7 Level 7 (23,880 points)
    Currently Being Moderated
    Oct 14, 2012 6:19 PM (in response to pheonixfire)

    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.

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.