I have a struct declared in .m file of Class A:
typedef struct myStruct
{
size_t count;
} myStruct;
And I am trying to pass it as parameter to a method in another class (Class B) in which I #import the .h file of class A (i.e. #import "myClassA.h"):
- (void)myMethodWithStructInClassB:(myStruct)aStruct
{
}
I got these error, respectively, when I did:
- (void)myMethodWithStructInClassB:(struct myStruct*)aStruct
Declaration of type struct aStruct will not be visible outside of this function.
- (void)myMethodWithStructInClassB:(struct myStruct)aStruct
Variable has incomplete type myStruct aStruct
I have then tried using #include instead, still the errors exist.
By the way, what would be the difference using #include and #import in Objective-C? I have done some research, while they were answers but they were not helpful for my case here. Some say with #import we prevent double-including the header, but the arguments were not settled between answerers.
I managed to fix the problem only when I did: #import "myClassA.m" (not .h).
Can some one explain to me the (a) errors above and (b) the difference between the use of #include and #import in Objective-C and (c) why importing .m did the trick for me?
In addition, which would be the proper way to do, when passing struct as parameter in Objective-C? i.e. #import or #include?