Xcode清除另一个类中的可变数组

问题描述 投票:0回答:1

在Xcode v6.4中,我有一个计算器应用,有计算器和大脑两个类。 在Brain中,有一个名为opperandStack的可变数组,我想从计算器类中清除opperandStack的内容。 我想从计算器类中清除 operandStack 的内容。 这是否可行,如果可以,如何做到? 我已经试过了(得到编译器错误)。

[self.brain operandStack removeAllObjects];

[self.brain.operandStack removeAllObjects];

在Brain中,我已经声明了属性@property (nonatomic, strong) NSMutableArray * operandStack; 综合@synthesize operandStack = _operandStack; 在Calculator类中的[self.brain.opperandStack removeAllObjects]仍然得到同样的编译器错误。

arrays xcode class mutable
1个回答
0
投票
[self.brain.operandStack removeAllObjects];

将会工作,但 只是 如果你声明 operandStack 作为 财产 在Brain.h中。

@property (nonatomic, strong) NSMutableArray *operandStack;

(并在Brain. m中加入合成器):

@synthesize operandStack;

我怀疑 operandStack 目前是Brain中的一个局部或实例变量。

© www.soinside.com 2019 - 2024. All rights reserved.