How to start and stop function using getter and setter?

In .h file

@interface ViewController : UIViewController {
            @private int intVariable1;
    }
    @property (readwrite,assign) int iVar;

    -(void)Callme;
    @end

In .m file

@implementation ViewController
@synthesize iVar=intVariable1;

-(void)Callme
{
        NSLog(@”Callme called”);
}

-(void)setIVar:(int)inIVar
{
        intVariable1 = inIVar;
        [self Callme];
}
@end

I have implement this code to call "Callme" function when the variable state changes, But when i call the function setIVar in viewDid load it does not work, Any idea of calling this? Way i used to call

[self setIVar:3];

Answers


If you want to provide your own implementation for getter/setter functions do not use the @synthesize directive in your implementation! This will generate its own -(void)setIVar:(int)inIVar and -(int)iVar methods and these might hide your version. In turn, if you want a readwrite property, you'll also have to implement the getter i.e. -(int)iVar.

Simple remove the @synthesize iVar=intVariable1; line from your implementation and put implement also -(int)iVar.


Need Your Help

how to match specific text link with php regex

php regex preg-match-all

here I'm looking for a regular expression in PHP which would match the anchor with a specific "target="_parent" on it.I would like to get anchors with text like: