If you want this to work as written you'd need to change it to:
NSLog(@"Second value==> %@", F.S.Just);
And on your First
object you'd need to add a @property
to expose the S
property (and synthesize it).
Frage
I want to assign value for NSString *just which is in the Second NSObject from the First NSObject and I want to access the Assigned value from the Viewcontroller.
I tried the above code It doesn't work for me.
It returns null
What i am doing wrong??
This is my first Viewcontroller :
#import <UIKit/UIKit.h>
#import "First.h"
#import "Second.h"
@interface testAppViewController : UIViewController
{
First *F;
Second *S;
}
@end
This is my .m of Viewcontroller :
F =[[First alloc]init];
[F Add];
NSLog(@"Second value==> %@",S.Just);
This is my First NSobject class.h
@interface First : NSObject
{
Second *S;
}
-(void)Add;
This is First NSObject class.m
#import "First.h"
@implementation First
-(void)Add{
NSString *c;
c =@"hi";
S=[[Second alloc]init];
[S setJust:c];
}
@end
This is my Second NSobject .h
@interface Second : NSObject
@property(nonatomic,strong)NSString *Just;
@end
This is Second NSObject .m
@implementation Second
@synthesize Just;
@end
Lösung
If you want this to work as written you'd need to change it to:
NSLog(@"Second value==> %@", F.S.Just);
And on your First
object you'd need to add a @property
to expose the S
property (and synthesize it).
Andere Tipps
The 'S' object you are trying to print Just value, is not the same 'S' object you set the value 'hi'.
These are two different instances. The first one is an instance of the view Controller, and the second one is an instance of 'First' class, object F.
Got it?