So what is actually the difference between these two versions:
@interface Foo : NSObject
// A guy walks into a bar.
@property(nonatomic, copy) NSString *bar;
@end
// Implementation file
@interface Foo ()
@property(nonatomic, retain) NSArray *baz;
@end
and
@interface Foo : NSObject
// A guy walks into a bar.
@public
@property(nonatomic, copy) NSString *bar;
@private
@property(nonatomic, retain) NSArray *baz;
@end
As far as my understanding goes, putting the @property in the .m basically means that it is private. Correct me if I am wrong? Also which is the best implementation then? Is it just a coding style/practice?
The compiler can warn you about things that it knows about.
When I import your header the compiler can see that
Foohas a method calledbarandsetBar:. This means I can use them bothwhereas because I only imported the header – the compiler can only see the header it is not aware that there are also methods
bazandsetBaz:available, so doing the following will cause the compiler to barfI can however still access these properties if I know they exist by using KVC like this without the compiler barfing