2016-10-09 44 views
0

属性值我已阅读,这样无法读取扩展

类扩展还专为允许财产公开readonly,私下readwrite

所以我做了一个有CLAS abc下面的代码:

@interface abc() 

@property (strong,nonatomic) NSString *sampleString; 

@end 

@implementation abc 


    @end 

我想在abc

我做了一个类pqr子类abc

另一个类的子类来acceess sampleStringpqr我正在尝试访问sampleStr但不是可以做到这一点。

@implementation cccc 

    - (void)accessPrivateMember 
{ 
    self.sampleStr ; //Not able to acces 

} 

@end 

我的方向错了吗?

+0

因为'sampleString'不在类的公共接口中。在你的类的'.h'文件中声明这个属性。 – Adeel

+0

在abc.h中添加只读属性作为@property(强,非原子,只读)NSString * sampleString; – kaushal

回答

0

您应该将属性放在头文件(.h)中。在你的情况下,sampleString是私有属性,因为它在实现文件(.m)中。另外,如果你想要访问私有财产,你可以使用self.valueForKey("sampleStr")

0

你应该在abc的'.h'文件中公开这个属性。加上:

@property (strong,nonatomic) NSString *sampleString;