Sketchの例では、次の値が返さ-[<NSCopying> copyWithZone:]
れる場合、inはチェックされません。-[<NSObject> init]
nil
- (id)copyWithZone:(NSZone *)zone {
SKTGraphic *copy = [[[self class] alloc] init];
copy->_bounds = _bounds;
copy->_isDrawingFill = _isDrawingFill;
copy->_fillColor = [_fillColor copy];
copy->_isDrawingStroke = _isDrawingStroke;
copy->_strokeColor = [_strokeColor copy];
copy->_strokeWidth = _strokeWidth;
return copy;
}
これは、それが戻った場合nil
(つまりバグ)、実行時にnull逆参照があることを意味します。
プログラムでリターンがあるかどうか-[<NSCopying> copyWithZone:]
をチェックしないのは普通ですか?私もこれをすべきではありませんか?私はこれについて:-[<NSObject> init]
nil
- (id)copyWithZone:(NSZone *)zone {
SKTGraphic *copy = [[[self class] alloc] init];
if (copy) {
copy->_bounds = _bounds;
copy->_isDrawingFill = _isDrawingFill;
copy->_fillColor = [_fillColor copy];
copy->_isDrawingStroke = _isDrawingStroke;
copy->_strokeColor = [_strokeColor copy];
copy->_strokeWidth = _strokeWidth;
}
return copy;
}