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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:23:54+00:00 2026-05-29T07:23:54+00:00

Please help, I’m stuck with objective-c global variables aka extern! I writing my first

  • 0

Please help, I’m stuck with objective-c global variables aka extern!
I writing my first iOS app it is a game, so to save my progress I wrote some global variables in Globals.h:

@interface Globals : NSObject
extern float square;
extern float field;
extern float dx;
extern float dy;
extern NSURL *documentsUrl;
extern NSURL *dbUrl;
extern NSString *savePath;
extern FMDatabase *db;
@end

And Globals.m:

#import "Globals.h"

@implementation Globals

float square;
float field;
float dx;
float dy;

NSURL *documentsUrl;
NSURL *dbUrl;
NSString *savePath;
FMDatabase *db;

+(void)initialize
{
    static BOOL initialized = NO;
    if (!initialized)
    {
        initialized = YES;
        square = 177.7778;
        field = 146.0;
        dx = 105;
        dy = 58.5;

        documentsUrl = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
        dbUrl = [documentsUrl URLByAppendingPathComponent:@"alias.sql"];
        [[NSFileManager defaultManager] copyItemAtURL:[[NSBundle mainBundle] URLForResource:@"alias" withExtension:@"sql"] toURL:dbUrl error:nil];
        savePath = [[documentsUrl URLByAppendingPathComponent:@"save.plist"] path];
        db = [FMDatabase databaseWithPath:[dbUrl path]];
        //db.logsErrors = YES;
        //db.traceExecution = YES;
        if (![db open]) {
            NSLog(@"Could not open db.");
        }
    }
}

@end

I make asured that initialize method executes at least once as app launched. In MainViewController which is my RootViewController in viewDidLoad method I use:

[GameInfo hasSave];

Which is a static method in GameInfo class and look like:

+(BOOL)hasSave
{
    return [[NSFileManager defaultManager] fileExistsAtPath: savePath];
}

And when I trace it the savePath is something like:

/Users/Apple/Library/Application Support/iPhone Simulator/5.0/Applications/472969F1-3760-4C74-8C8D-29681F47F4CB/Documents/save.plist

But then I execute IBAction on Touch up inside in the same view, in the same time which look like:

if ([GameInfo hasSave])
{
    [GameInfo load];
}

And when I make a step in method hasSave I have some strange savePath value:

ar.lproj

And my method of course returns me NO. But it occurs not only with my savePath, but with all other extern variables. And sometimes they are correct but sometimes they are not.
I think maybe the problem is where I use them, maybe I forgot something to do. Please help me.

P.S.: Sorry about my English and a huge quastion.

  • 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-29T07:23:55+00:00Added an answer on May 29, 2026 at 7:23 am

    your [[NSFileManager defaultManager] fileExistsAtPath: savePath]; will return NO as there exits the savePath but there doesn’t exists the file as you haven’t created it in

    +(void)initialize
    

    ~~~~~~~~~~~~~~~~~ edited ~~~~~~~~~~~~~~~~~~~~
    use extern NSString *savePath; in your GameInfo.h or .m

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

Sidebar

Related Questions

Please help, I am stuck here --- irb> a = line of text\n line
Please Help me to do this first i have this div <div class=loader alt=stat.php>
please help so here is the problem i got a rails app that sends
please help me. I want to print some reports from .NET app. I read
Please help in writing a code for conversion of source data in dd/mm/yyyy format.
please help on this issue: Within a loop, I first call a function, which
Please help me in resolving this issue. I'm writing a java SOAP client to
Please help! I'm really at my wits' end. My program is a little personal
Please help! Background info I have a WPF application which accesses a SQL Server
Please help me with a sanity check. Assuming a many-to-many relationship: Post, PostTagAssoc, Tag

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.