ashish
ashish

Reputation: 787

how to pass variable one class to other class by method in objective c

let for consider the code

one.h
#import "historyViewController.h"

int isItfsa;


one.m
     -(IBAction)homeHistory:(id)sender{
            isItfsa = 0;
            historyViewController *hisVController = [[historyViewController alloc]initWithNibName:@"historyViewController" bundle:nil];
            [self presentModalViewController:hisVController animated:YES];
            [hisVController release];
        }

But when i receive it does not print //0

but in 2nd class two.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    NSLog(@"isItfsa=%@",isItfsa); //isItfsa=null
}

it is print null ,but why? and how i can pass the value from one class to another class by method.

Upvotes: 0

Views: 120

Answers (2)

Jim
Jim

Reputation: 5960

isItfsa is defined by your code as an int, which is not an object. Your NSLog is formatted for printing an object using %@. If the int value is zero, then trying to print it as an object will yield (null).

Your print statement should be NSLog(@"isItfsa=%d",isItfsa);

Upvotes: 2

Sulthan
Sulthan

Reputation: 130102

Null is the same value as zero. It writes "null" because you don't tell it to write an integer, you are telling it to write an object.

Your code:

NSLog(@"isItfsa=%@",isItfsa) (write isItfsa as object)

It should be:

NSLog(@"isItfsa=%i",isItfsa) (write isItfsa as integer)

Upvotes: 1

Related Questions