0

SSharedAppState.h

#import <Foundation/Foundation.h>

enum {
    SharedCompletedStepNone    = 0,
    SharedCompletedStepOne     = 1 << 0,
    SharedCompletedStepTwo      = 2 << 1,
    SharedCompletedStepThree   = 3 << 2
};
typedef NSUInteger SharedCompletedSteps;

@interface SSharedAppState : NSObject
{
    struct {
        unsigned int sharedCompletedStepMask:3;
    } _appFlags;
}
@property (assign, nonatomic) SharedCompletedSteps sharedCompletedStep;

+(id)sharedInstance;
@end

SSharedAppState.m

#import "SSharedAppState.h"

#pragma mark - C functions


#pragma mark - Interface Extension

typedef struct _appFlags AppFlags;
@interface SSharedAppState ()

@property (unsafe_unretained, nonatomic) AppFlags *appFlags;
-(void *)newAppFlags;
@end

#pragma mark - Implementation

@implementation SSharedAppState
@synthesize appFlags;

#pragma mark - Iniitalizer

-(id)init
{
    self = [super init];
    if (self) {

//        appFlags = (AppFlags *)malloc(sizeof(_appFlags));
        appFlags = (AppFlags *)newAppFlags();
        appFlags->sharedCompletedStepMask = 0;
        appFlags.sharedCompletedStepMask = 0;
    }
    return self;
}

+(SSharedAppState *)sharedInstance
{
    static dispatch_once_t onceToken;
    static id sharedInstance;
    dispatch_once(&onceToken, ^{
        sharedInstance = [[self alloc] init];
    });
    return sharedInstance;
}

#pragma makr - Struct _appFlags

-(void *)newAppFlags
{
    AppFlags *instance = (AppFlags *)malloc(sizeof(_appFlags));
    return instance;
}


@end

Questions

  1. appFlags = (AppFlags *)newAppFlags();

gives implicit declaration of function newAppFlags is invalid in C99

  1. appFlags->sharedCompletedStepMask = 0; appFlags.sharedCompletedStepMask = 0;

Incomplete definition of type 'struct _appFlags' Member reference type 'AppFlags *' (aka 'struct _appFlags *') is a pointer; maybe you meant to use '->'?

Gives following warnings and error. These is my first time to post questions here so please advice on html or editing. Thankyou!

0

1 Answer 1

2

When you write like this

struct {
    unsigned int sharedCompletedStepMask:3;
} _appFlags;

you are declaring a variable _appFlags of an unnamed struct.

you probably meant

struct _appFlags {
    unsigned int sharedCompletedStepMask:3;
};

or you could write

typedef struct _appFlags {
    unsigned int sharedCompletedStepMask:3;
} AppFlags;
Sign up to request clarification or add additional context in comments.

2 Comments

i made the necessary changes but still not able to bind my sharedCompletedStepMask and sharedCompletedStep i am trying to understand why apple would keep similar implementation in UIView or UITableView if for not maintaining a state machine which is what i want to do for my application.
well can't use typedef in @interface { typedef ... }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.