-3

Here is my code:

secondClass.h

@property (nonatomic) int number;

secondClass.m

@synthesize number;


  //positioning object in x position of first class

  object.center = CGPointMake(number, object.center.y);


  NSLog(@"%d",number);

first class.m

#import "secondClass.h"
secondClass *second = [secondClass alloc];
second.number = 15;

I used NSLog to see what is happening. In the first class, the value of the second number is 15. When I used NSLog to see it's value in the second class, it comes up as 0.

What am I doing wrong?

Sev
  • 15,401
  • 9
  • 56
  • 75
user3215624
  • 55
  • 11

4 Answers4

0

maybe you just have a typo in your description but try:

secondClass *second = [[secondClass alloc] init];  
second.number = 15;  
NSlog(@"number is:%d",number);  
hfossli
  • 22,616
  • 10
  • 116
  • 130
CocoaEv
  • 2,984
  • 20
  • 21
  • tried with initializing it now.. but still result is the same. Still got 0 in secondClass.m output. – user3215624 Mar 18 '14 at 18:18
  • Can you post your actual code (since the NSLog is missing, and some code posted here is incorrect). Consider this: Your code doesn't do what you want it to do. So don't keep code away from us because you assume it is correct. It isn't. – gnasher729 Mar 18 '14 at 22:23
0

Try to synthesize your number in secondClass.m

@synthesize number;

and add the init in your secondClass declaration

hope this help.

0

Find a similar case. The thing is that I'm using segue for transition from one view controller to another. I solved out problem with method prepareForSegue. Here is the code I was searching:

  -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if([segue.identifier isEqualToString:@"NextView"]){
    secondClass *second = (secondClass *)segue.destinationViewController;
    second.number = object.center.x;
   }
}
user3215624
  • 55
  • 11
0
@property (readwrite) int number;

//first class

    second *move = [[second alloc] initWithNibName:@"second" bundle:nil];
    move.number = 15;
    [self.navigationController pushViewController:move animated:YES];
    [move release];
Bhavesh Nayi
  • 3,626
  • 1
  • 27
  • 42