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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:13:19+00:00 2026-06-11T10:13:19+00:00

In my .m file I’ve declared this variable static NSString* MyGlobalPassword; and in the

  • 0

In my .m file I’ve declared this variable

static NSString* MyGlobalPassword;

and in the .m file I have a class method I’m calling in another class to get an NSString

    + (NSString *) updateMessageString: (NSString *) msgString
{
    MyGlobalPassword = msgString;

    return MyGlobalPassword;
}

I want to access MyGlobalPassword in an instance method of the same class

 - (void) Access
    {
        NSLog(@"I've retrieved it %@", MyGlobalPassword);
    }

Objective-C throws an unrecognized selector error when I try to do this. It doesn’t want to let me access that variable in an instance method. How can I force it too?

  • 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-11T10:13:20+00:00Added an answer on June 11, 2026 at 10:13 am

    I suspect you get the error because your static variable isn’t initialized. It’s generally not a good idea to declare variables in your .h files as they can’t be included in many places that way (without additional work and headache). You probably want to extern the declaration in your header like this:

    extern NSString* MyGlobalPassword;
    

    And declare it in your .m like this:

    NSString* MyGlobalPassword;
    

    Additionally, you usually will not want to make globals like this. Either you should have a singleton class that gets allocated once and used in many places or you should have this be a class member. You can also cheat and do the above, but make it static in the .m file and add class accessors to get at it everywhere.

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

Sidebar

Related Questions

file c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config doesn't have this element. Where these options are keeping?
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
file://localhost/C:/Users/kürşat/Desktop/yeni%20site/faq%20-%20Kopya/kopya.html this is my photography tutorial page. I'm did manage to toggle on/off when
File: /home/USER/DIR/a http://www.here.is.a.hyper.link.net/ /home/USER/DIR/b http://www.here.is.another.hyper.link.net/ Need to remove all the odd lines in this
FILE #1 (foo.h): #ifndef FOO_H_ #define FOO_H_ #include baseclass.h #include bar.h class Bar; class
// File: foo.c static int var; void foo() { var++; } // end of
I have just tried to save a simple *.rtf file with some websites and
File ex1.hpp (definition of template class): #ifndef EX1_HPP #define EX1_HPP #include ex2.hpp template <class
File A.h #ifndef A_H_ #define A_H_ class A { public: virtual ~A(); virtual void
FILE *file = fopen([gpsFilePath UTF8String], r); char c[1024]; while(fgets(c, 1024, file)!=NULL) { NSString *cString

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.