Is there any reason to declare a private ivar in @interface
instead of @implementation
?
I see code like this all over the internet (including documentation provided by Apple):
Foo.h
@interface Foo : NSObject {
@private
id _foo;
}
@end
Foo.m
@implementation Foo
// do something with _foo
@end
The header file defines the public interface of a class, whereas a private ivar is... well... private. So why not declare it like this?
Foo.h
@interface Foo : NSObject
@end
Foo.m
@implementation Foo {
@private
id _foo;
}
// do something with _foo
@end
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…