Objective-C How do I return a struct datatype?

objective-c

Solution

Objective-C is a based on C not C++. In `C` we need to use `struct Line`, while in C++ `Line` is fine.

You can do this as :

struct {
    NSUInteger x1;
    NSUInteger x2;
} Line;

// ...

- (struct Line)visibleLine{
    
}

OR

struct Line {
    NSUInteger x1;
    NSUInteger x2;
};
typedef struct Line Line;

// ...

- (Line)visibleLine;

Above is preferred by most C frameworks.

Also,

typedef struct {
    NSUInteger x1;
    NSUInteger x2;
} Line;

// ...

- (Line)visibleLine;

Problem

``` struct Line { NSUInteger x1; NSUInteger x2; }; // ... - (Line)visibleLine; ``` The code above obviously doesn't work because Line is not a valid type. Any suggestions?

Original source