How to pass (by value) a structure in Objective-C?

This one is driving me crazy! I have a structure:

typedef struct{
  int a;
}myStruct;

Then I:

myStruct tempStruct;

I am trying to pass a structure to a class method whose implementation:

- (void) myFunc:(struct myStruct)oneOfMyStructs{};

I call the method as follows:

[myClass myFunc:(struct myStruct)tempStruct];

The compiler complains about the "Convert to non-scalar type" request. All I want to do is pass the structure to the class method, but the syntax is a bit confusing to me. I am new to Objective-C. Please let me know if you see where I am wrong. I also could not follow the link, so if you could help me with this, that would be great!

Thank!

+3
source share
1 answer

typedef -ed myStruct, (, ) struct :

typedef struct tag_myStruct
{
    int a;
}
myStruct;

- (void) myFunc:(myStruct) x {}

[myClass myFunc:tmpStruct];

. ( Cocoa, , NSRect s.)

+3

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


All Articles