Ojective C Class or struct?

Posted by Scott Pendleton on Stack Overflow See other posts from Stack Overflow or by Scott Pendleton
Published on 2010-04-02T14:39:14Z Indexed on 2010/04/02 14:43 UTC
Read the original article Hit count: 139

Filed under:
|
|
|

I have a class Song with properties Title, Key, Artist, etc. There are no methods. I loop through a database of song information and create a Song object for each, populating the properties, and then store the Song objects in an NSArray.

Then I thought, why not just have a struct Song with all those same properties instead of a class Song. Doing so would eliminate the class files, the #import Song line in the using class's .m file, and the need to alloc, init, release.

On the other hand, I'd have to put the struct definition in every class that might need it. (Unless there's some globally accessible location -- is there?) Also, can a struct be stored in an NSArray?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about class