Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8295553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:38:42+00:00 2026-06-08T14:38:42+00:00

i am new to objective c. i have added an interface in one class

  • 0

i am new to objective c. i have added an interface in one class file and i have declared some variables there . while compiling it shows “Cant declare variable inside @interface and @protocol” error in all the declaration.
this is the sample code

#import "State.h"

@interface State(private)
NSString *forgotPassword=nil;
NSMutableArray *CategorySelection = nil;
NSMutableArray *subCategorySelection= nil;
NSString *string = nil;
int Tag= 0;
int alertTag=0;
NSURL *stringURL =nil;
NSURL *videoURL =nil;
NSURL *imageURL = nil;
int loginCount = 0;
NSMutableArray *album;
NSString *videoFileName = nil;
int videoCounting=0;
int loginUserId = 0;
int ImageTagg = 0;

@end

@implementation State

+(void) setforgotPasswordText:(NSString *) passwordText{
    forgotPassword = passwordText;
}

I am the beginner , so guide me to fix this issue. thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T14:38:44+00:00Added an answer on June 8, 2026 at 2:38 pm

    If you just want to declare a new class, State, you declare your instance variables as such (inside braces, no explicit initialization):

    @interface State
    {
        NSString *forgotPassword;
        NSMutableArray *categorySelection;
        NSMutableArray *subCategorySelection;
        NSString *string;
        int tag;
        int alertTag;
        NSURL *stringURL;
        NSURL *videoURL;
        NSURL *imageURL;
        int loginCount;
        NSMutableArray *album;
        NSString *videoFileName;
        int videoCounting;
        int loginUserId;
        int imageTag;
    }
    @end
    

    If you’re using ARC, you don’t need to initialize them, because it will set all of these to zero or nil. If you’re not using ARC (but why wouldn’t you), you’d initialize these in your init method.

    And I notice that you’re writing your own “setter” (e.g. setForgotPassword). If you want the compiler to do this for you (i.e. to “synthesize” them for you), first declare these variables as properties, e.g.:

    @interface State
    
    @property (nonatomic, strong) NSString *forgotPassword;
    @property (nonatomic, strong) NSMutableArray *categorySelection;
    @property (nonatomic, strong) NSMutableArray *subCategorySelection;
    @property (nonatomic, strong) NSString *string;
    @property int tag;
    @property int alertTag;
    @property (nonatomic, strong) NSURL *stringURL;
    @property (nonatomic, strong) NSURL *videoURL;
    @property (nonatomic, strong) NSURL *imageURL;
    @property int loginCount;
    @property (nonatomic, strong) NSMutableArray *album;
    @property (nonatomic, strong) NSString *videoFileName;
    @property int videoCounting;
    @property int loginUserId;
    @property int imageTag;
    
    @end
    

    And having declared the properties, you can now let the compiler synthesize the “setters” and “getters”. For these @property declarations, if you’re using the latest compiler (Xcode 4.4 … came out a week or so ago) you don’t need to explicitly @synthesize them anymore in your @implementation. But if you’re using an earlier compiler, you need to include @synthesize for all of your @property declarations, e.g.

    @implementation State
    
    @synthesize forgotPassword = _forgotPassword;
    @synthesize categorySelection = _categorySelection;
    @synthesize subCategorySelection = _subCategorySelection;
    @synthesize string = _string;
    // etc.
    

    If you do that (declare a @property and then @synthesize it), the compiler will, behind the scenes, create the instance variable for you and then automatically generate a “setter” (i.e. a method that is “set” followed by your variable name, e.g. “setForgotPassword”) and a “getter” method (a method with the same name as your variable which will retrieve the variable contents for you) for each of your properties. Note, for all of these properties, the @synthesize forgotPassword = _forgotPassword will also generate the instance variable, but by including an underscore before the ivar name, you’ll ensure you won’t confuse the property self.forgotPassword with the instance variable _forgotPassword.

    If you wanted it to be a category (basically the addition of new methods to be applied to an existing class, designated by referencing an existing class, State followed by a category designator, State (private)), then you can’t include new variables. I don’t know if that was really your intent (I doubt it). But, if you really want to do that but you really need these new variables, you could instead subclass your existing State class, as follows:

    @interface StateSubClass : State
    {
        NSString *forgotPassword;
        NSMutableArray *categorySelection;
        NSMutableArray *subCategorySelection;
        NSString *string;
        int tag;
        int alertTag;
        NSURL *stringURL;
        NSURL *videoURL;
        NSURL *imageURL;
        int loginCount;
        NSMutableArray *album;
        NSString *videoFileName;
        int videoCounting;
        int loginUserId;
        int imageTag;
    }
    @end
    

    And if you’ll notice, I also changed your variable names to conform to Apple conventions of initial lowercase letter. Classes start with uppercase, variables start with lowercase.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new in objective-C and i wonder if its correct: I have a class
I am new to objective-c. I have the following: @interface HPSEnumerations : NSObject typedef
I'm very new to Objective-C, and am having some beginner issues. I have an
I have a brand new Objective-C class called test . The test class has
I am relatively new to Objective C and need some array help. I have
I'm very new to Objective-C, and am having some beginner issues. I have an
I am new to Objective-C and I have no clue why this code is
I am new to Objective-C and iPhone I have to sort a NSDictionary using
I am relatively new to Objective-C / iPhone programming, and have only created single
I'm new to objective C and currently working on a small project. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.