我有以下方法,其中創建一個NSMutableArray
並添加一些值到它:的NSMutableArray要零
NSMutableArray * pointsForInterpolation = [[NSMutableArray alloc] init];
//Code to add objects to array
我然後設定爲等於通過執行予分配的相同的方法中的以下的數組的屬性並初始化所述陣列:
self.wavePoints = pointsForInterpolation;
self.wavePoints是一個NSMutableArray屬性,它是強(@property(nonatomic,strong) NSMutableArray *wavePoints;
)。然後我執行以下操作:
-(void) setWavePoints:(NSMutableArray *)wavePoints
{
_wavePoints = wavePoints;
NSLog(@"_wavePoints count %lu", [_wavePoints count]);
}
我的NSLog顯示_wavePoints有一個有效的計數並且不爲零。我去,直到我到了這最後的方法來執行無關與陣列其他一些方法:
- (UIBezierPath*) createPath
{
NSLog(@"Wave points count %lu", [_wavePoints count]);
NSMutableArray* data = [self.wavePoints mutableCopy];
NSLog(@"ARRay count 2 %lu", [data count]);
}
頁眉:
@interface OSWaveView()
@property(nonatomic,strong)AVAsset *audioAsset;
@property(nonatomic,strong) NSMutableArray *wavePoints;
@property (nonatomic, strong) NSMutableArray * pointsForInterpolation;
@property(nonatomic,assign)CGFloat minAmpl;
@property(nonatomic,assign)CGFloat maxAmpl;
@property (nonatomic, strong) CAShapeLayer* blueWave;
@property (nonatomic, strong) CAShapeLayer* redWave;
@end
最後兩個的NSLog的顯示計數爲零。我的初始數組(pointsForInterpolation)正在發佈嗎?
爲什麼你需要可變地複製你的財產?你不應該已經保留它強烈嗎? – Aaron
此外,您可能需要仔細檢查並查看其他對象可能會調用'-setWavePoints:',併發送可能會意外更改'self.wavePoints'的東西... – Aaron
對不起'mutableCopy'是舊代碼,應該有已被刪除。我環顧四周,無法找到任何會在我不知情的情況下調用self.wavePoints的內容。 – Brosef