Right method of accessing properties of objects inside other objects in Objective-C
I have a Singleton Class SharedDataObject which has a another class object myClass. MyClass h开发者_运维知识库as BOOL variables as well. I provided accessors (nonatomic,retain) for MyClass and (assign, readwrite) to myClass Instance variables. I have also synthesized each one of them. But when I access them to read value or write value with
[[SharedDataObject getInstance].myClass available];
OR
[[SharedDataObject getInstance].myClass setAvailable:YES];
It gives me following warning:
no 'available:' method found
no 'setAvailable' method found
But I can read and write values to it. I want to remove warnings. What am I doing wrong? Or if it is a wrong way to access it?
Class Declarations are:
@interface SharedDataObject : NSObject {
MyClass *myClass;
}
@property (nonatomic, retain) MyClass *myClass;
+ (SharedDataObject*) getInstance;
@end
@interface MyClass : NSObject {
BOOL available;
}
@property (assign, readwrite) BOOL available;
@end
Check this:
- Include the .h for
MyClass
The singleton's myClass property returns(answered in update to question)MyClass*
, not some base-class
What happens if you do
[SharedDataObject getInstance].myClass.available
If I've understood you well, your myClass is a class property of your SharedDataObject class, so you cannot access it as it was a instance property.
Can you provide us with the full declaration of the classes?
Does
[[SharedDataObject myClass] available]
works?
精彩评论