我正在查看PSPDFkit示例代码并看到了这个:
NSDictionary *options = @{kPSPDFProcessorAnnotationTypes :
@(PSPDFAnnotationTypeNone & ~PSPDFAnnotationTypeLink)
};
常量PSPDFAnnotationTypeNone
和PSPDFAnnotationTypeLink
定义如下:
// Available keys for options. kPSPDFProcessorAnnotationDict in
// form of pageIndex -> annotations.
// ..
extern NSString *const kPSPDFProcessorAnnotationTypes;
// Annotations defined after the PDF standard.
typedef NS_OPTIONS(NSUInteger, PSPDFAnnotationType) {
PSPDFAnnotationTypeNone = 0,
PSPDFAnnotationTypeLink = 1 << 1, // Links and multimedia extensions
PSPDFAnnotationTypeHighlight = 1 << 2, // (Highlight, Underline, StrikeOut) -
PSPDFAnnotationTypeText = 1 << 3, // FreeText
PSPDFAnnotationTypeInk = 1 << 4,
PSPDFAnnotationTypeShape = 1 << 5, // Square, Circle
PSPDFAnnotationTypeLine = 1 << 6,
PSPDFAnnotationTypeNote = 1 << 7,
PSPDFAnnotationTypeStamp = 1 << 8,
PSPDFAnnotationTypeRichMedia = 1 << 10, // Embedded PDF videos
PSPDFAnnotationTypeScreen = 1 << 11, // Embedded PDF videos
PSPDFAnnotationTypeUndefined = 1 << 31, // any annotation whose type not recognized
PSPDFAnnotationTypeAll = UINT_MAX
};
我知道这~
是按位非运算符和&
按位与运算符,但是它们在此代码中的应用目的是什么?
NSDictionary *options = @{kPSPDFProcessorAnnotationTypes :
@(PSPDFAnnotationTypeNone & ~PSPDFAnnotationTypeLink)
};
根据下面的评论,上面可以简单地写成
NSDictionary *options = @{kPSPDFProcessorAnnotationTypes :@(PSPDFAnnotationTypeNone)};
既然是一样的(0 & ~2) => 0
。添加& ~PSPDFAnnotationTypeLink
零件有什么意义?