How do I pass (by value) a struct in Objective-C?

Posted by Striker on Stack Overflow See other posts from Stack Overflow or by Striker
Published on 2010-05-01T22:43:44Z Indexed on 2010/05/01 22:47 UTC
Read the original article Hit count: 217

Filed under:
|
|

This one has been driving me mad! I have a struct:

typedef struct{
  int a;
}myStruct;

Then I have:

myStruct tempStruct;

I am trying to pass the struct to a class method whose implementation is:

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

I call the method like so:

[myClass myFunc:(struct myStruct)tempStruct];

The compiler complains about "Conversion to non-scalar type requested." All I want to do is pass a struct into a class method, but the syntax has me a bit confused. I'm new to Objective-C. Please let me know if you can see where I'm going wrong. I've not been able to pass by reference either, so if you could help me out with that, that would be great!

Thanks!

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about struct