我想检查变量何时为僵尸,何时不为僵尸,我具有类似这样的功能,其中y必须从超层中删除(如果它确实存在),有时它已被删除,但是作为僵尸,它崩溃了在这一点上。为了在运行时检查变量是否为僵尸,该怎么办?
if (avPlayerLayer) {
[avPlayerLayer removeFromSuperlayer];
}
我有以下代码可以创建它:
if (!avPlayer) {
avPlayer = [[AVPlayer alloc] initWithURL:movieURL];
} else {
[avPlayer replaceCurrentItemWithPlayerItem:[AVPlayerItem playerItemWithURL:movieURL]];
avPlayer.rate = 0.0f;
}
}
avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:avPlayer];
我应该做这样的事情吗?
if (!avPlayer) {
avPlayer = [[AVPlayer alloc] initWithURL:movieURL];
} else {
avPlayer = nil;
avPlayer = [[AVPlayer alloc] initWithURL:movieURL];
avPlayer.rate = 0.0f;
}
}
avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:avPlayer];
有什么帮助吗?先感谢您!
最佳答案
为什么不将变量设置为nil,然后检查nil。
关于objective-c - 当变量是僵尸还是不是?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9416118/