开发者

structs in objective-C

where do you define a str开发者_开发技巧uct in an objective-C class. The header file?

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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜