Tuesday 15 April 2014

ios - Subclassing view controller: Forward declaration -



ios - Subclassing view controller: Forward declaration -

i have been next rule of having:

@myclassname in header file of class

&&

#import "myclassname" in implementation

i have decided subclass 1 of view controllers. if overwrite method next message:

receiver 'myclassname' class message forwards declaration

to on come need set #import header file doesn't seem follow thought best practices.

can explain if have misunderstood utilize of @class?

or if dong things correctly, can please explain need break best practices , utilize #import in header file when subclassing?

many thanks.

edit:

thanks answers. think need add together more detail clarify situation , understanding. here header base of operations class:

#import <uikit/uikit.h> #import "coreplot-cocoatouch.h" @class organisation; @interface longcalldetailviewcontroller : uiviewcontroller <uitableviewdelegate, uitableviewdatasource>

in impementation have

#import "organisation.h"

my subclass header contains following:

#import "longcalldetailviewcontroller.h" @interface longcallsubclassviewcontroller : longcalldetailviewcontroller @end

if override method in subclass , seek utilize organisation object gives me error stated above. hence either need add together #import "organisation.h" base of operations classes header or duplicate #import "organisation.h" subclasses implementation file. both of seem wrong me.

many thanks.

within header files, should importing other header files classes subclass. not need import header files classes referenced , not subclassed. example, header file might like:

#import "mysuperclass.h" @class myobjecttype; @interface mysubclass : mysuperclass @property (strong) myobjecttype *value; @end

edit: based on new edits, looks writing header files correctly. when declare @class in scope, not able access of selectors or properties associated class. okay declare using @class in places not intending utilize selectors or properties of class type , pass around reference (as in header have described above), want else object, you'll need have imported header file describing @interface.

when defining @class myobjecttype in header file, expected #import "myobjecttype.h" appears in associated source file. header files intended declaration of structure, whereas source files contain implementation. example, source file associated header file described above might like:

#import "mysubclass.h" #import "myobjecttype.h" @implementation mysubclass - (void)overriddenfunction { [self.value anobjecttypeselector]; } @end

you shouldn't think "duplicating" import statement when they're in 2 different scopes. when forwards declare @class organisation in longcalldetailviewcontroller header file, you'll have #import "organisation.h" in longcalldetailviewcontroller source file. if need access object's properties , selectors in longcallsubclassviewcontroller class, you'll need #import "organisation.h" in longcallsubclassviewcontroller implementation file. remember: implementation files not know content of each other; know contents of header file.

ios objective-c subclassing

No comments:

Post a Comment