Darren Findlay
Darren Findlay

Reputation: 2563

structs in objective-C

where do you define a struct in an objective-C class. The header file?

Sorry if this is a total noob question, Thanks in advance.

Upvotes: 0

Views: 442

Answers (2)

Max
Max

Reputation: 16709

I tell you a little secret: 'id' type is pointer to the structure. So you actually using them all the time. However sometimes it is more convenient to use plain C structures:

  1. you need to pass some data via Bluetooth and want to minimize the traffic
  2. you want to pass some data to the C/C++ function as parameter
  3. you are using some legacy library.

So as Objective C is the superset of C all the rules from C are applied to Objective C. It means you can declare struct everywhere, where C allows it: in the header if you want this struct to be public or in an implementation file.

Upvotes: 2

Macmade
Macmade

Reputation: 54049

Depends if your struct needs to be public...

If so, define it in the header file (interface). If not, you can define it in the implementation file.

Upvotes: 0

Related Questions