Help with understanding C # code and porting to Objective-C

Ok, I have this prototype written by someone else in C #, and I'm trying to put it in Objective-C. Now I have not had a formal experience with C #, so I do not know everything about it yet. I understand what the first three variables are, but I'm having problems with what the fourth and fifth lines do (c_data). Is the fourth declaration a method, and then the fifth, defining it or what happens? Thank you for your help!

public class c_data {
    public double value;
    public int label;
    public int ID;
    public c_data() { }
    public c_data(double val) {
        value = val;
    }
}
+3
source share
7 answers

#. [[c_data alloc] init] objective-c. # , . Objective-C:

@interface CData : NSObject
{
   double value;
   int label;
   int ID;
}

@property double value;
@property int label;
@property int ID;

-(id) init;
-(id) initWithValue:(double)value;

@end
+16

4- - , 5- - .

+2

c_data no-args , ( → 0.0, label → 0, ID → 0), c_data - , pass-in val, - . , .

+2

4- 5- , c_data, .

+1

- , , , - val.

+1

4- 5- .

- , .

5- value .

+1

, Objective-C:

  • (ID) initialization;
  • (id) initWithNumber: (NSNumber *) number;

Constructors and initializers are analogs; they are just slightly different.

0
source

Source: https://habr.com/ru/post/1712472/


All Articles