I want to implement a class which can be used by two classes of my project.
One is manipulating ‘NewsRecord’ objects.
One is manipulating ‘GalleriesRecord’ objects.
In another class, I may use one of the two objects so i do something like that :
// header class
id myNewsRecordOrGalleriesRecord;
// class.m
// NewsRecord and GalleriesRecord have both the title property
NSLog(myNewsRecordOrGalleriesRecord.title);
and i get :
error : request for member 'title' in something not a structure or union
any ideas 😀 ?
Thanks.
Gotye
How am I supposed to do it ?
You can’t use dot syntax on
idtypes because the compiler cannot know whatx.foomeans (the declared property may make the getter a different name, e.g.view.enabled -> [view isEnabled]).Therefore, you need to use
or
If
titleand more stuffs are common properties of those two classes, you may want to declare a protocol.BTW, don’t use
NSLog(xxx);, which is prone to format-string attack and you can’t be certainxxxis really an NSString. UseNSLog(@"%@", xxx);instead.