In Xcode4.4, I found I can use a method define in .m file directly without declaration in .h head file or .m file.
what's the rule of method declaration in Obj-c? Could I use a method without declaration in head file?
In Xcode4.4, I found I can use a method define in .m file directly without declaration in .h head file or .m file.
what's the rule of method declaration in Obj-c? Could I use a method without declaration in head file?
If you declare a method in the header file, then other classes will be able to access that method.
performSelector:
and it will succeed at runtime. –
Guthrie You import headers whenever you want to use the methods declared in the headers.
So if you have created a class called ObjectA
then to be able to use the methods you have declared in ObjectA.h
you need to import it #import "ObjectA.h"
.
You usually only need to do the imports in your implementation .m
files. If you need it in your header file you can use the @class
annotation like this:
@class ObjectA
...
@property (nonatomic, strong) ObjectA *objectA;
© 2022 - 2024 — McMap. All rights reserved.