Gurpal Rajput
Gurpal Rajput

Reputation: 41

How to Access instance Variable of one class to another class in objective c?

this is the code for.m class of first viewcontroller[][1]I had tried accessing value of IVAR of one viewcontroller to another viewcontroller by making use of property , but i am getting null value.

please let me know how to get value displayd in my secondviewcontroller.

enter image description here

Upvotes: 0

Views: 321

Answers (1)

trungduc
trungduc

Reputation: 12154

You are doing the right way to get value of property. But you need to make sure myString has been assigned a value in init method of ViewController.

Try in ViewController.m:

- (instancetype)init {
    self = [super init];

    if (self) {
        self.myString = @"My String";
    }

    return self;
}

Beside of it, make sure that myMetod of SecondViewController is called. If myMetod is called, "Print value My String" will be printed.

Upvotes: 1

Related Questions