开发者

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:

  1. Include the .h for MyClass
  2. The singleton's myClass property returns MyClass*, not some base-class (answered in update to question)


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜