objective c - Can cocoa framework hide an ivar declaration in their public header file? -
is possible ?
my colleague told me naming ivar prefix underscore apple may cause problem. said apple can declare ivar in class , doesn't let in public header file. if accidentally name ivar collide "secret ivar" not in header file , cause problem.
i don't know how frameworks works i'm not sure explanation. know apple reserve use of prefix underscore method name in there code guideline , many people use prefix underscore when name ivar , said it's safe because if name collide compiler generate error. know true if name of ivar in header file. kind of "secret ivar" not in public header file?
my colleague's evidence if dump apple's application framework's header file , compare apple's public header file, find don't match many declaration of both methods , ivars.
i'm confused question , hope can provide professional answer , if can provide reliable reference question , great help.
(i don't know whether have explain question enough... forgive poor english...)
your colleague might referring instance variables in class extensions. not show in (public) interface of class. instance,
// someclass.h -- publicly distributed file @interface someclass : nsobject @end // someclass.m -- known framework developer @interface someclass() { nsstring *someivar; } @end @implementation someclass - (id)init { self = [super init]; if (self) someivar = @"default"; return self; } @end note has access public headers won’t know someclass has instance variable called someivar reading header file declares class. also, won’t possible access instance variable in same way accessing instance variable declared in public interface. in fact, there won’t name collision in case developer subclasses someclass , declares instance variable named someivar. instance, valid:
// somesubclass.h @interface somesubclass : someclass { nsstring *someivar; } @end in case, reference someivar in implementation of somesubclass refer instance variable declared in somesubclass only, , instance variable different 1 declared in (private) class extension of someclass.
the compiler emits different symbol names them:
_objc_ivar_$_someclass.someivar_objc_ivar_$_somesubclass.someivar
and, upon instantiating object of type somesubclass, both instance variables located in different memory addresses.
while inspection of binary might show someclass has instance variable called someivar though it’s not listed in public header file, there won’t name collision in subclasses.
that said, might possible apple have set of public header files distribute sdk use alternative, private header files declare additional instance variables. find rather unlikely , there might potential binary incompatibility if happens. guess apple able provide definitive answer.
Comments
Post a Comment