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 6999123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:30:01+00:00 2026-05-27T20:30:01+00:00

I have declared a variable NSString sessionId; in app delegate file for global usage.

  • 0

I have declared a variable NSString sessionId; in app delegate file for global usage.

In appdelegate.h

@property (strong, nonatomic) NSMutableString *sessionId;

In appdelegate.m

@synthesize sessionId;

And used it in one of my view controller like this.

    ((VektorAppDelegate *)[UIApplication sharedApplication].delegate).sessionId = sID.retain;

NSLog(@"session id = %@", ((VektorAppDelegate *)[UIApplication sharedApplication].delegate).sessionId);

I am able to accèss that variable sessionId in all of my view controllers but the issue is that the value is not getting saved in it. Like in viewcontroller1.m, I assigned it some value but when I accessed sessionId in another viewcontroller2.m, its showing its value as null on console.

How can I resolve this issue.

Code added:

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
     NSString *responseString = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding];

self.receivedData = nil;


    NSError *error;

    SBJSON *json = [[SBJSON new] autorelease];

    NSArray *session = [json objectWithString:responseString error:&error];

    SBJsonParser *parser =[[SBJsonParser alloc] init];

    NSDictionary *jsonObject = [parser objectWithString:responseString];

    sID = [jsonObject objectForKey:@"session"];

    ((VektorAppDelegate *)[UIApplication sharedApplication].delegate).sessionId = sID;

    NSLog(@"session id = %@", ((VektorAppDelegate *)[UIApplication sharedApplication].delegate).sessionId);


    NSUserDefaults *sessID = [NSUserDefaults standardUserDefaults];

    [sessID setObject:sID forKey:@"sessionID"];

    [sessID synchronize];

    NSLog(@"This session %@ saved", sID);

    NSDictionary *accountsObj = [parser objectWithString:responseString];

    NSString *accounts = [accountsObj objectForKey:@"account"];

    NSArray *accountList = [accounts componentsSeparatedByString:@","];

    NSLog(@"Accounts: %@", accountList);


    if (session == nil)
    NSLog(@"JSON parsing failed: %@", [error localizedDescription]);
else {

    if (accountList.count > 1) {

        ChooseAccountsController *accountsView = [[ChooseAccountsController alloc] initWithNibName:@"ChooseAccountsController" bundle:nil ];

        self.chooseAcc = accountsView;

        [self.view addSubview: accountsView.view];
    } else if (accountList.count == 1) {

            MainScreenController *mainScreen1 = [[MainScreenController alloc] initWithNibName:@"MainScreen" bundle:nil ];

             self.mainScreen = mainScreen1;

             [self.view addSubview: mainScreen1.view];

         }
    }

}
  • 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-05-27T20:30:02+00:00Added an answer on May 27, 2026 at 8:30 pm
    ((VektorAppDelegate *)[UIApplication sharedApplication].delegate).sessionId = sID.retain;
    

    is not valid code, try

    ((VektorAppDelegate *)[UIApplication sharedApplication].delegate).sessionId = sID
    

    a strong property should be retaining, and also retain is a message, so if you need this (not in this case) the only correct syntax is [anObject retain]

    try

    ((VektorAppDelegate *)[UIApplication sharedApplication].delegate).sessionId = [jsonObject objectForKey:@"session"];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a global NSString variable that I declared in my ViewController.m file, outside
I have an NSString declared as @property (nonatomic,copy) NSString *text in a class. When
I have a NSString member variable declared in the header file of the view
I have a weird problem. pictureLink is a global variable declared in .h NSString
I have a NSString declared in the interface part: @property (nonatomic, retain) NSString *filePath;
In following program . I have one doubt. I have declared one global variable
I have a vector declared as a global variable that I need to be
I have a instance variable declared as a retain property & then I released
I have an instance variable declared in the implementation file which can be accessed
I have one .xib file with an App Delegate. In this App Delegate, I

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.