小编Len*_*sen的帖子

Objective-C:访问继承类中的私有属性

我正在尝试访问继承类的私有属性.那可能与苹果给我的命名惯例有关吗?

标题:

#import <Foundation/Foundation.h>

@interface FooBar : NSObject
-(void)doSomeThingWithThisNumber:(NSInteger)aNumber;
@end
Run Code Online (Sandbox Code Playgroud)

执行:

#import "FooBar.h"


@interface FooBar()
@property NSInteger myPrivateFoo;
@end


@implementation FooBar
@synthesize myPrivateFoo = _myPrivateFoo;

-(void)doSomeThingWithThisNumber:(NSInteger)aNumber
{
    _myPrivateFoo = aNumber;
}

@end
Run Code Online (Sandbox Code Playgroud)

如果我将这个类继承到一个我无法访问的新类_myPrivateFoo.还有另一种方法来代替头文件中的声明吗?

inheritance properties private objective-c

7
推荐指数
1
解决办法
3473
查看次数

标签 统计

inheritance ×1

objective-c ×1

private ×1

properties ×1