0

I am using 2 nsobject class ,

First nsobject class some property and it holds some values. In Second NSObject class i want to access the first nsobject class properties. I have tried little bit ,it showing null values Here is my code My First NSObject class FieldData.M

-(instancetype)initWithDictionary:(NSDictionary *)dictFieldData
{
if (self = [super init]) {

    ///set the field id
    self.fieldId = [[dictFieldData objectForKey:@"f_id"]intValue];
    self.display = [[dictFieldData objectForKey:@"f_display"]boolValue];
    self.fieldLength = [[dictFieldData objectForKey:@"f_length"]intValue];
    self.mandatory = [[dictFieldData objectForKey:@"f_mandatary"]boolValue];
    self.strFieldLabel = [dictFieldData objectForKey:@"f_label"];

    NSString *strFieldAttrib = [dictFieldData objectForKey:@"f_attribute"];
    if ([strFieldAttrib.lowercaseString isEqualToString:@"alpha"]) {

        self.fieldAttribute = FieldAttributeAlpha;
    }
    else if ([strFieldAttrib.lowercaseString isEqualToString:@"numeric"]) {

        self.fieldAttribute = FieldAttributeNumeric;
    }
    else if ([strFieldAttrib.lowercaseString isEqualToString:@"alpha_numeric"]) {

        self.fieldAttribute = FieldAttributeAlphaNumeric;
    }

    }return self;
    }

****Second NSObjectClass** SiteData.m**

-(instancetype)initWithDictionary:(NSDictionary *)dictSiteData
{

self.fieldData = [FieldData new];

if (self = [super init]) {


    self.siteId = [[dictSiteData objectForKey:@"s_id"]intValue];

    self.siteName = [dictSiteData objectForKey:@"site_name"];

    NSLog(@"%d",self.fieldData.fieldId);





}

return self;
}

Please anyone helpme to do this Please what i am doing wrong Thanks in Advance !!!

Agal Sivamanoj
  • 111
  • 1
  • 11

2 Answers2

0

[FieldData new] will by default invoke the init method, not the initWithDictionary one. Unless you've defined init to set values for your property it will default to nil. You probably need to create your object using [[FieldData alloc] initWithDictionary:...] (or [FieldData newWithDictionary:...] if you've defined that method). HTH

CRD
  • 52,522
  • 5
  • 70
  • 86
  • i have used still it is showing null values .Plesae anyone helpme – Agal Sivamanoj Oct 24 '16 at 06:49
  • @AgalSivamanoj - Edit your question and show the interface for `FieldData`, all it's `init` and `new` members, and the revised `SiteData` code which creates the `FieldData` instance. – CRD Oct 24 '16 at 07:34
0

Please write this code in Appdelegate declare this property. After that SetValue your Dictionary Data

@property(strong,nonatomic)NSDictionary * dictFieldData;

Write this code My First NSObject class FieldData.M Create object in ViewdidLoad

 AppDelegate *appdelegate ((AppDelegate *)[[UIApplication sharedApplication] delegate]);


///set the field id
self.fieldId = [[appdelegate.dictFieldData SetValue:(NSString*) objectForKey:@"f_id"]intValue];

///Get the field id
self.siteId = [[appdelegate.dictSiteData Valueforkey:@"s_id"]intValue];

NSLog(@"%d",appdelegate.dictSiteData);

Check this post answer for Accessing Property from another NSObjectClass

Community
  • 1
  • 1
Himanshu Patel
  • 1,015
  • 8
  • 26
  • @thnaks ,Himanshu Patel , i want to access the property in second nsobject clss only ,how can i do that please help me – Agal Sivamanoj Oct 24 '16 at 06:52
  • @thanks Himanshu Patel , working fine ,one more thing User *userData = [[User alloc]initWithDictionary:userProfileData]; – Agal Sivamanoj Oct 24 '16 at 08:23
  • User *userData = [[User alloc]initWithDictionary:userProfileData]; AZCAppDelegate *delegate = [[UIApplication sharedApplication]delegate]; delegate.userProfiels = userData; – Agal Sivamanoj Oct 24 '16 at 08:24
  • User *userData = [[User alloc]initWithDictionary:userProfileData]; AZCAppDelegate *delegate = [[UIApplication sharedApplication]delegate]; delegate.userProfiels = userData; this delegate.userProfiles has one array ,that contains nsobejct ,how can i access that nsobject property – Agal Sivamanoj Oct 24 '16 at 08:26
  • Sorry i didnt downvote it , i just put a tick mark only , i dont have that much reputation – Agal Sivamanoj Oct 24 '16 at 08:27