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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:27:16+00:00 2026-05-22T11:27:16+00:00

Of Objective C, I’m looking to call a variable from one .m to the

  • 0

Of Objective C, I’m looking to call a variable from one .m to the other .m

This is given myvar declared as an int in Example1.h

Example1.m

myvar = myvar+10

Example2.m

if (myvar == 10){NSLOG("@myvar equals the correct integer: %i",myvar);}

However, by default myvar will equal 0 because myvar is called from Example1.h in Example2.m.

  • 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-22T11:27:17+00:00Added an answer on May 22, 2026 at 11:27 am

    For global values, create a class to hold these and define the variables as static. You can also define class level methods to manipulate the static variable. I call my class appState. You might define myVar as static and then class methods (use the + not -) to get and set this variable.

    Here’s an example of a BOOL I can access from anywhere in my application.

    account.h

    #import <Foundation/Foundation.h>
    
    @interface Account : NSObject 
    {
    }
    
    +(BOOL)isOffLine;
    +(void)setOffLine:(BOOL)newValue;
    
    @end
    

    account.m

    #import "Account.h"
    
    @implementation Account
    
    static BOOL _offline;
    
    +(BOOL)isOffLine;
    {
        return _offline;
    }
    
    +(void)setOffLine:(BOOL)newValue
    {
        _offline = newValue;
    }
    
    @end
    

    Now from any class in my application, I can #import account.h and then use something like:

    if ([Account isOffLine]) {...}
    

    or

    [Account setOffLine:YES];
    

    Note that I didn’t create an instance of this class. I’m calling the class level methods. The value will persist between calls from different classes in my application.

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

Sidebar

Related Questions

Objective-C has no namespaces; it's much like C, everything is within one global namespace.
Objective-C uses a sophisticated message-passing system when one object calls a method on another
My objective is to get the answer from up to 6000 Urls in the
Objective-C / Cocoa: I need to load the image from a JPG file into
Objective-C newbie question. Given the following (fictional) code: id mysteryObject = [anotherObject mysteriousMethod]; How
( Objective C ) How would I call a base class function using a
Objective C answers are fine too. This is in C# Monotouch. Currently I am
Objective-J is compiled/transformed into JavaScript directly on the browser. (This is contrast to doing
Objective-C/iPhone beginner here...looking for a shove in the right direction. I need to create
Objective: To prevent users from tampering any id (example: CustomerId, UserId, ProductId, etc) between

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.