A
A
Alexey FRZ2016-05-16 21:40:11
Objective-C
Alexey FRZ, 2016-05-16 21:40:11

Objects in objective c. How to determine?

Objects are instances of a class, in order to use the class code, we need to create an object.

@interface Person : NSObject {
    NSString *_name; 
    NSInteger _age;
}

Here, in the newly created Person class, two variables _name & _age are declared. The star sign is placed only near the object. Why is the object exactly _name? What if I create a class to find the area of ​​a triangle using a single formula? There are only 4 variables, the area of ​​the triangle, side A, side B and height. What will be the object here and marked with an asterisk? If this is the area of ​​a triangle, how will it be declared?
double *_areaTriangle; // ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2016-05-16
@leshqow

The "star sign" is placed where you declare not a variable, but a pointer to it. Accordingly, what you want - then declare it as pointers, if you need it.
Specifically, in the example with a triangle, I would not make any pointers. And the area is not a variable, but a method. The class is a triangle, with parameters - sides and a method - "calculate area", "calculate perimeter", etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question