Set value to a class object which is property of another class - Objective c

student

It's difficult for me to express my problem so I will write a simple example of it. I have 2 classes, MyclassA and MyclassB.

@interface MyclassA
@property (nonatomic, assign) int *ID;
@property (nonatomic, strong) MyclassB *secondclass;
@end

@implementation MyclassA

-(id)init
{
self.ID = 1;
MyclassB *sec = [[MyclassB alloc] init];
sec.age = 10;
sec.weight = 35;
self.secondclass = sec;

return self;
}

MyclassB:

@interface MyclassB
@property (nonatomic, assign) int age;
@property (nonatomic, assign) int weight;
@end

When I place a breakpoint at

return self;

the value of self.secondclass is null.

What am I doing wrong?

Jitendra Solanki

You are creating a new object of the MyClassB. You should initialize the property secondClass in the init method instead of assigning the reference of another instance of MyClassB.

-(id)init
{
  self.ID = 1;
  self.secondclass = [[MyclassB alloc] init];
  self.secondclass.age = 10;
  self.secondclass.weight = 35;

  return self;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Setting a Class Object as a property of another Class in Objective-C

From Dev

Objective-C Set Property from Another Class Returns Null

From Dev

Objective-C : Calling a property of a class in another

From Dev

Objective C: array of class object as property

From Dev

HQL is unable to understand a class's property which is a set of another class

From Dev

Objective c pass slider value to another class

From Dev

Set property values of an Objective-C class using reflection

From Dev

Add Item from another class to a property from another class. Objective-C

From Dev

Add Item from another class to a property from another class. Objective-C

From Dev

What is the best way to pass an object to another class in Objective-C?

From Dev

Access to variable value from another class in Objective C

From Dev

get value of an object in another class

From Dev

Set a variable for a class from an object and access the same value from another object of that class

From Dev

Initializing Objective-C property in child class

From Dev

dynamic initialize any objective C class with property

From Dev

detect the class of a property with name in objective-c

From Dev

dynamic initialize any objective C class with property

From Dev

Objective-C class for property with name

From Dev

Access property from outside a class in objective c

From Dev

accessing class property which is added by frord declaration from another class

From Dev

C#/VB - change the value of a property of a class (object)

From Dev

Sending NSNumber to another class method - Objective C

From Dev

Access NSMutableArray from another class - Objective C

From Dev

Updating variables of another class objective c

From Dev

how To set and pass value of variable which also accesible in another View objective C

From Dev

How to get and set private instance variable/ property from outside a class Objective C?

From Dev

How to get and set private instance variable/ property from outside a class Objective C?

From Java

Unable to access Swift 4 class from Objective-C: "Property not found on object of type"

From Dev

Remove value from array which belongs to different class objective-c

Related Related

  1. 1

    Setting a Class Object as a property of another Class in Objective-C

  2. 2

    Objective-C Set Property from Another Class Returns Null

  3. 3

    Objective-C : Calling a property of a class in another

  4. 4

    Objective C: array of class object as property

  5. 5

    HQL is unable to understand a class's property which is a set of another class

  6. 6

    Objective c pass slider value to another class

  7. 7

    Set property values of an Objective-C class using reflection

  8. 8

    Add Item from another class to a property from another class. Objective-C

  9. 9

    Add Item from another class to a property from another class. Objective-C

  10. 10

    What is the best way to pass an object to another class in Objective-C?

  11. 11

    Access to variable value from another class in Objective C

  12. 12

    get value of an object in another class

  13. 13

    Set a variable for a class from an object and access the same value from another object of that class

  14. 14

    Initializing Objective-C property in child class

  15. 15

    dynamic initialize any objective C class with property

  16. 16

    detect the class of a property with name in objective-c

  17. 17

    dynamic initialize any objective C class with property

  18. 18

    Objective-C class for property with name

  19. 19

    Access property from outside a class in objective c

  20. 20

    accessing class property which is added by frord declaration from another class

  21. 21

    C#/VB - change the value of a property of a class (object)

  22. 22

    Sending NSNumber to another class method - Objective C

  23. 23

    Access NSMutableArray from another class - Objective C

  24. 24

    Updating variables of another class objective c

  25. 25

    how To set and pass value of variable which also accesible in another View objective C

  26. 26

    How to get and set private instance variable/ property from outside a class Objective C?

  27. 27

    How to get and set private instance variable/ property from outside a class Objective C?

  28. 28

    Unable to access Swift 4 class from Objective-C: "Property not found on object of type"

  29. 29

    Remove value from array which belongs to different class objective-c

HotTag

Archive