Builds and runs no problem:
@interface Foo : NSObject
@property (readonly) id foo;
@end
@implementation Foo
- (instancetype)init
{
self = [super init];
if (self)
{
_foo = [NSObject new];
}
return self;
}
@end
int main(int argc, const char * argv[])
{
@autoreleasepool {
Foo *foo = [Foo new];
NSLog(@"%@", foo.foo);
}
return 0;
}
Compiler error:
@interface Foo : NSObject
@property (readonly) id foo;
@end
@implementation Foo
- (instancetype)init
{
self = [super init];
if (self)
{
_foo = [NSObject new];
}
return self;
}
- (id)foo
{
return _foo;
}
@end
int main(int argc, const char * argv[])
{
@autoreleasepool {
Foo *foo = [Foo new];
NSLog(@"%@", foo.foo);
}
return 0;
}
My point was that providing _foo in some methods and not others is not a sensible or intuitive implementation.