0

I'm trying to set a BOOL value that needs to be checked within another file where I do the XML parching.

Its like this in filename.m:

    if (internetConnectionStatus == NotReachable) {

        //SET A BOOL VALUE TO FALSE

    } else {    

        //SET A BOOL VALUE TO TRUE

    }

And in XMLParserfile.m I need to check whether the BOOL value set in filename.m is TRUE or FALSE

    if (BOOLVALUEORSOMETHING == TRUE) {

        //DO THIS

    } else {    

        //DO THAT

    }

This could be a stupid question, but what is the best way to do this.

Andreas
  • 5
  • 3

3 Answers3

2

Use it as a property.

@property (nonatomic, assign) BOOL number;
Legolas
  • 12,145
  • 12
  • 79
  • 132
0

Something like this should work. I'm not sure your entire goal, so it some cases you might actually want to use static classes or methods instead.

filename.h:

#import <Foundation/Foundation.h>

typedef enum {
NotReachable
} InternetConnectionStatus;

@interface filename : NSObject
{
    BOOL isReachable;
}

@property BOOL isReachable;

@end

filename.m:

#import "filename.h"

@implementation filename
@synthesize isReachable;

- (id)init
{
    self = [super init];
    if (self) {
        // Initialization code here.        
        InternetConnectionStatus internetConnectionStatus = NotReachable;
        if (internetConnectionStatus == NotReachable) {

            //SET A BOOL VALUE TO FALSE
            self.isReachable = FALSE;

        } else {    

            //SET A BOOL VALUE TO TRUE
            self.isReachable = TRUE;
        }                
    }

    return self;
}

@end

XMLParserfile.h:

#import <Foundation/Foundation.h>

@interface XMLParserfile : NSObject

@end

XMLParserfile.m:

#import "XMLParserfile.h"
#import "filename.h"

@implementation XMLParserfile

- (id)init
{
    self = [super init];
    if (self) {
        // Initialization code here.
        filename *file = [[filename alloc] init];

        if(file.isReachable == TRUE)
        {
            // DO THIS
        }
        else
        {
            // DO THAT.
        }
    }

    return self;
}

@end
mservidio
  • 12,817
  • 9
  • 58
  • 84
-1

You can do this in one of several ways. I've discussed that in this answer to another question.

Community
  • 1
  • 1
Moshe
  • 57,511
  • 78
  • 272
  • 425